Browse Source

advanced hops on xml data extraction (task not completed)

pull/3/head
psy 11 years ago
parent
commit
f9cb99647c
  1. 67
      main.py
  2. 2
      web/index.py
  3. 20
      xml_exporter.py

67
main.py

@ -47,6 +47,11 @@ class bc(object):
self.city = ""
self.country = ""
self.server_name = ""
self.hop_count = 1 # number of hops
if os.path.exists('data.xml'): # removing xml data to has a new map each time that bc is launched
os.remove('data.xml')
open('data.xml', 'w') # starting a new xml data container in write mode
def set_options(self, options):
"""
@ -231,6 +236,7 @@ class bc(object):
# Set database (GeoLiteCity)
self.geoip = pygeoip.GeoIP('GeoLiteCity.dat')
self.geoasn = pygeoip.GeoIP('GeoIPASNum.dat')
self.hop_count = 1
print '='*45 + "\n", "Current target:\n" + '='*45 + "\n"
print "URL:", self.url[0], "\n"
@ -276,6 +282,8 @@ class bc(object):
logfile.write(item)
print '='*45 + "\n" + "Packages Route:\n" + '='*45
for line in a.stdout:
self.hop_count = self.hop_count + 1
if self.options.debug == True:
logfile.write(line)
parts = line.split()
@ -286,7 +294,6 @@ class bc(object):
asn = self.geoasn.org_by_addr(ip)
except:
asn = 'nothing'
#print record
try:
self.hop_host_name = socket.gethostbyaddr(ip)[0]
@ -304,25 +311,29 @@ class bc(object):
if record.has_key('country_name') and record['city'] is not '':
country = record['country_name']
city = record['city']
print "Trace:", count, "->", ip, "->", city, "->", country, "->", self.hop_host_name, asn
print "Trace:", count, "->", ip, "->", longitude + ":" + latitude, "->", city, "->", country, "->", self.hop_host_name, asn
count+=1
self.city = city
self.country = country
self.server_name = self.hop_host_name
elif record.has_key('country_name'):
country = record['country_name']
print "Trace:", count, "->", ip, "->", country, "->", self.hop_host_name, asn
print "Trace:", count, "->", ip, "->", longitude + ":" + latitude, "->", country, "->", self.hop_host_name, asn
self.country = country
self.server_name = self.hop_host_name
count+=1
except:
print "Trace:", count, "->", "Not allowed"
count+=1
# write xml data to file
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
if self.options.debug == True:
logfile.close()
self.old_url = url
self.hop_count = 0 # to start a new map
print "\n"
def getGEO(self):
"""
@ -401,6 +412,12 @@ class bc(object):
url = self.try_running(self.getURL, "\nInternal error getting urls from browser's database.")
# set geoip database
geo = self.try_running(self.getGEO, "\nInternal error setting geoIP database.")
# run traceroutes
match_ip = self.url[0].strip('http://').strip(':8080')
if re.match(r'^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$', match_ip) or re.match(r'^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$', match_ip) or re.match(r'^192.168\.\d{1,3}$', match_ip) or re.match(r'^172.(1[6-9]|2[0-9]|3[0-1]).[0-9]{1,3}.[0-9]{1,3}$', match_ip):
pass
else:
traces = self.try_running(self.traces, "\nInternal error tracerouting.")
# start web mode (on a different thread)
try:
t = threading.Thread(target=BorderCheckWebserver, args=(self, ))
@ -414,29 +431,6 @@ class bc(object):
webbrowser.open('http://127.0.0.1:8080', new=1)
except:
print "Error: Browser is not responding correctly.\n"
# run traceroutes
match_ip = self.url[0].strip('http://').strip(':8080')
if re.match(r'^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$', match_ip) or re.match(r'^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$', match_ip) or re.match(r'^192.168\.\d{1,3}$', match_ip) or re.match(r'^172.(1[6-9]|2[0-9]|3[0-1]).[0-9]{1,3}.[0-9]{1,3}$', match_ip):
self.ip = 'localhost'
self.longitude = '-'
self.latitude = '-'
self.city = '-'
self.country = '-'
self.server_name = '-'
pass
else:
self.ip = '' #this is overwritten
self.longitude = '-'
self.latitude = '-'
self.city = '-'
self.country = 'waiting'
self.server_name = 'waiting'
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
traces = self.try_running(self.traces, "\nInternal error tracerouting.")
# export data to XML
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
print '='*45 + "\n"
print "Status: Waiting for new urls ...\n"
@ -447,26 +441,9 @@ class bc(object):
match_ip = url.strip('http://').strip(':8080')
if url != self.old_url:
if re.match(r'^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$', match_ip) or re.match(r'^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$', match_ip) or re.match(r'^192.168\.\d{1,3}$', match_ip) or re.match(r'^172.(1[6-9]|2[0-9]|3[0-1]).[0-9]{1,3}.[0-9]{1,3}$', match_ip):
self.ip = 'localhost'
self.longitude = '-'
self.latitude = '-'
self.city = '-'
self.country = '-'
self.server_name = '-'
pass
else:
self.ip = '' #this is overwritten
self.longitude = '-'
self.latitude = '-'
self.city = '-'
self.country = 'waiting'
self.server_name = 'waiting'
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
traces = self.try_running(self.traces, "\nInternal error tracerouting.")
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
if __name__ == "__main__":
app = bc()

2
web/index.py

@ -48,7 +48,7 @@ output = """
<link rel="stylesheet" href="style.css" />
<script src="js/leaflet/leaflet.js"></script>
<!--<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>-->
<meta http-equiv="refresh" content="5">
<meta http-equiv="refresh" content="3">
</head>
<body>
<center>

20
xml_exporter.py

@ -16,15 +16,19 @@ class xml_reporting(object):
def print_xml_results(self, filename):
root = ET.Element("travel")
host = ET.SubElement(root, "host")
ip = ET.SubElement(root, "ip")
longitude = ET.SubElement(root, "longitude")
latitude = ET.SubElement(root, "latitude")
city = ET.SubElement(root, "city")
country = ET.SubElement(root, "country")
server_name = ET.SubElement(root, "server_name")
meta = ET.SubElement(root, "meta")
i = 1
for i in range(self.instance.hop_count):
hop = ET.SubElement(root, "hop")
host = ET.SubElement(hop, "host")
ip = ET.SubElement(hop, "ip")
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")
meta = ET.SubElement(hop, "meta")
hop.text = str(i)
host.text = self.instance.url[0]
ip.text = self.instance.ip
longitude.text = self.instance.longitude

Loading…
Cancel
Save