2013-09-20 18:00:00 +02:00
|
|
|
#!/usr/local/bin/python
|
2013-09-09 21:05:39 +02:00
|
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
"""
|
|
|
|
BC (Border-Check) is a tool to retrieve info of traceroute tests over website navigation routes.
|
|
|
|
GPLv3 - 2013 by psy (epsylon@riseup.net)
|
|
|
|
"""
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
|
|
class xml_reporting(object):
|
|
|
|
"""
|
|
|
|
Print results from a traceroute in an XML fashion
|
|
|
|
"""
|
|
|
|
def __init__(self, bc):
|
|
|
|
# initialize main BC
|
|
|
|
self.instance = bc
|
|
|
|
|
|
|
|
def print_xml_results(self, filename):
|
|
|
|
root = ET.Element("travel")
|
2013-09-12 20:59:44 +02:00
|
|
|
i = 1
|
2013-09-12 23:34:19 +02:00
|
|
|
for i in self.instance.result_list:
|
2013-09-12 20:59:44 +02:00
|
|
|
hop = ET.SubElement(root, "hop")
|
|
|
|
host = ET.SubElement(hop, "host")
|
2013-09-12 23:34:19 +02:00
|
|
|
hop_ip = ET.SubElement(hop, "hop_ip")
|
2013-09-12 20:59:44 +02:00
|
|
|
longitude = ET.SubElement(hop, "longitude")
|
|
|
|
latitude = ET.SubElement(hop, "latitude")
|
|
|
|
city = ET.SubElement(hop, "city")
|
|
|
|
country = ET.SubElement(hop, "country")
|
|
|
|
server_name = ET.SubElement(hop, "server_name")
|
2013-09-12 23:34:19 +02:00
|
|
|
asn = ET.SubElement(hop, "asn")
|
2013-09-13 16:37:12 +02:00
|
|
|
timestamp = ET.SubElement(hop, "timestamp")
|
2013-09-12 20:59:44 +02:00
|
|
|
meta = ET.SubElement(hop, "meta")
|
2013-09-09 21:05:39 +02:00
|
|
|
|
2013-09-20 18:00:00 +02:00
|
|
|
root.text = i['url']
|
2013-09-12 23:34:19 +02:00
|
|
|
hop.text = str(i['hop_count'])
|
|
|
|
host.text = i['destination_ip']
|
|
|
|
hop_ip.text = i['hop_ip']
|
|
|
|
longitude.text = i['longitude']
|
|
|
|
latitude.text = i['latitude']
|
|
|
|
city.text = i['city']
|
|
|
|
country.text = i['country']
|
|
|
|
server_name.text = i['server_name']
|
|
|
|
asn.text = i['asn']
|
2013-09-13 16:37:12 +02:00
|
|
|
timestamp.text = i['timestamp']
|
2013-09-12 20:59:44 +02:00
|
|
|
meta.text = "Connect here XML metadata"
|
2013-09-09 21:05:39 +02:00
|
|
|
|
2013-09-12 20:59:44 +02:00
|
|
|
tree = ET.ElementTree(root)
|
|
|
|
tree.write(filename)
|
2013-09-09 21:05:39 +02:00
|
|
|
|