Browse Source

fixed error when some xml data fails. code checkpoint.

pull/3/head
psy 11 years ago
parent
commit
582efc2477
  1. 15
      main.py
  2. 52
      web/index.py

15
main.py

@ -251,10 +251,10 @@ class bc(object):
if self.method == '-e': if self.method == '-e':
self.method = '-E' self.method = '-E'
try: try:
self.content = subprocess.check_output(['lft', '-S', '-n', self.method, self.destination_ip]) self.content = subprocess.check_output(['lft', '-S', '-n', self.destination_ip])
# support for older python versions (<2.7) that don't support subprocess.check_output # support for older python versions (<2.7) that don't support subprocess.check_output
except: except:
a = subprocess.Popen(['lft', '-S', '-n', self.method, self.destination_ip], stdout=subprocess.PIPE) a = subprocess.Popen(['lft', '-S', '-n', self.destination_ip], stdout=subprocess.PIPE)
self.content = a.stdout.read() self.content = a.stdout.read()
self.attempts += 1 self.attempts += 1
@ -331,27 +331,21 @@ class bc(object):
self.attempts = 0 self.attempts = 0
self.result_list = [] self.result_list = []
self.lft() self.lft()
if self.options.debug == True: if self.options.debug == True:
logfile = open('tracelogfile', 'a') logfile = open('tracelogfile', 'a')
thingstolog = ['='*45 + "\n", "Browser: ", self.browser_path.split('/')[-1], "\n", "Version: ", self.browser_version, "\n", "Path to browser: ", self.browser_path, "\n", "History db: ", self.browser_history_path, "\n","URL: ", self.url[0], "\n", "Host: ",url, "\n", "Host ip: ", url_ip, "\n", '='*45, "\n"] thingstolog = ['='*45 + "\n", "Browser: ", self.browser_path.split('/')[-1], "\n", "Version: ", self.browser_version, "\n", "Path to browser: ", self.browser_path, "\n", "History db: ", self.browser_history_path, "\n","URL: ", self.url[0], "\n", "Host: ",url, "\n", "Host ip: ", url_ip, "\n", '='*45, "\n"]
for item in thingstolog: for item in thingstolog:
logfile.write(item) logfile.write(item)
print '='*45 + "\n" + "Packages Route:\n" + '='*45 print '='*45 + "\n" + "Packages Route:\n" + '='*45
output = self.content.splitlines() output = self.content.splitlines()
for line in output: for line in output:
if self.options.debug == True: if self.options.debug == True:
logfile.write(line+'\n') logfile.write(line+'\n')
line = line.split() line = line.split()
for ip in line: for ip in line:
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",ip): if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",ip):
self.hop_ip = ip self.hop_ip = ip
record = self.geoip.record_by_addr(ip) record = self.geoip.record_by_addr(ip)
try: try:
self.asn = self.geoasn.org_by_addr(ip) self.asn = self.geoasn.org_by_addr(ip)
@ -389,8 +383,9 @@ class bc(object):
self.vardict = {'destination_ip': self.destination_ip, 'hop_count': self.hop_count,'hop_ip': self.hop_ip, 'server_name': self.server_name, 'country': self.country, 'city': self.city, 'longitude': self.longitude, 'latitude': self.latitude, 'asn' : self.asn, 'timestamp' : self.timestamp } self.vardict = {'destination_ip': self.destination_ip, 'hop_count': self.hop_count,'hop_ip': self.hop_ip, 'server_name': self.server_name, 'country': self.country, 'city': self.city, 'longitude': self.longitude, 'latitude': self.latitude, 'asn' : self.asn, 'timestamp' : self.timestamp }
except: except:
print "Trace:", self.hop_count, "->", "Not allowed" print "Trace:", self.hop_count, "->", "Not allowed"
self.hop_count+=1 self.vardict = {'destination_ip': self.destination_ip, 'hop_count': self.hop_count,'hop_ip': self.hop_ip, 'server_name': self.server_name, 'country': '-', 'city': '-', 'longitude': '-', 'latitude': '-', 'asn' : self.asn, 'timestamp' : self.timestamp }
self.hop_count+=1
# write xml data to file # write xml data to file
self.result_list.append(self.vardict) self.result_list.append(self.vardict)
xml_results = xml_reporting(self) xml_results = xml_reporting(self)
@ -403,10 +398,8 @@ class bc(object):
logfile.close() logfile.close()
self.old_url = url self.old_url = url
self.hop_count = 0 # to start a new map self.hop_count = 0 # to start a new map
print "\n"
return return
def getGEO(self): def getGEO(self):
""" """
Get Geolocation database (http://dev.maxmind.com/geoip/legacy/geolite/) Get Geolocation database (http://dev.maxmind.com/geoip/legacy/geolite/)

52
web/index.py

@ -1,25 +1,21 @@
#new index.py #!/usr/bin/python
# -*- coding: ISO-8859-1 -*- # -*- coding: iso-8859-15 -*-
from lxml import etree """
BC (Border-Check) is a tool to retrieve info of traceroute tests over website navigation routes.
GPLv3 - 2013 by psy (epsylon@riseup.net)
"""
from xml.dom.minidom import parseString from xml.dom.minidom import parseString
import xml.etree.ElementTree as ET
# extract data from a xml file # extract data from a xml file
f = open('data.xml', 'r') f = open('data.xml', 'r')
f2 = open('data.xml', 'r') f2 = open('data.xml', 'r')
xml = etree.parse(f) xml = ET.parse(f)
data = f2.read() data = f2.read()
dom = parseString(data.encode('utf-8')) dom = parseString(data.encode('utf-8'))
f.close() f.close()
f2.close() f2.close()
n_hops = dom.getElementsByTagName('hop')[-1].toxml().replace('<hop>', '').replace('</hop','') n_hops = dom.getElementsByTagName('hop')[-1].toxml().replace('<hop>', '').replace('</hop','')
hoplist = [] hoplist = []
geoarray = [] geoarray = []
latlong= [] latlong= []
@ -27,26 +23,21 @@ latlong= []
b = '' b = ''
for counter in range(1, int(xml.findall('hop')[-1].text)+1): for counter in range(1, int(xml.findall('hop')[-1].text)+1):
hop = parseString(dom.getElementsByTagName('hop')[counter].toxml().encode('utf-8')) hop = parseString(dom.getElementsByTagName('hop')[counter].toxml().encode('utf-8'))
server_name = hop.getElementsByTagName('server_name')[0].toxml().replace('<server_name>','').replace('</server_name>','') server_name = hop.getElementsByTagName('server_name')[0].toxml().replace('<server_name>','').replace('</server_name>','')
asn = hop.getElementsByTagName('asn')[0].toxml().replace('<asn>','').replace('</asn>','') asn = hop.getElementsByTagName('asn')[0].toxml().replace('<asn>','').replace('</asn>','')
hop_ip = hop.getElementsByTagName('hop_ip')[0].toxml().replace('<hop_ip>','').replace('</hop_ip>','') hop_ip = hop.getElementsByTagName('hop_ip')[0].toxml().replace('<hop_ip>','').replace('</hop_ip>','')
longitude = hop.getElementsByTagName('longitude')[0].toxml().replace('<longitude>','').replace('</longitude>','') longitude = hop.getElementsByTagName('longitude')[0].toxml().replace('<longitude>','').replace('</longitude>','')
latitude = hop.getElementsByTagName('latitude')[0].toxml().replace('<latitude>','').replace('</latitude>','') latitude = hop.getElementsByTagName('latitude')[0].toxml().replace('<latitude>','').replace('</latitude>','')
point = """ L.marker(["""+latitude+""", """+longitude+"""]).addTo(map)
.bindPopup("<b>"""+server_name+"""</b><br />"""+hop_ip+"""<br />"""+asn+"""<br />").openPopup(); """
latlong = [float(latitude.encode('utf-8')), float(longitude.encode('utf-8'))]
geoarray.append(latlong)
hoplist.append(point) point = """ L.marker(["""+latitude+""", """+longitude+"""]).addTo(map)
.bindPopup("<b>"""+server_name+"""</b><br />"""+hop_ip+"""<br />"""+asn+"""<br />").openPopup(); """
b = b+point latlong = [float(latitude.encode('utf-8')), float(longitude.encode('utf-8'))]
geoarray.append(latlong)
test = open('test.html','w')
hoplist.append(point)
b = b+point
output = """ output = """
<html> <html>
@ -78,6 +69,3 @@ output = """
</body> </body>
</html> </html>
""" """
test.write(output)
test.close
Loading…
Cancel
Save