From 437772b205c8546774fa6c5753b206b99dbb54e8 Mon Sep 17 00:00:00 2001 From: rscmbbng Date: Mon, 16 Sep 2013 15:20:17 +0200 Subject: [PATCH] now tries subprocess.popen if subprocess.check_output fails. added map drawing feature in index.py --- main.py | 9 ++- web/index.py | 155 +++++++++++++++++++++------------------------------ 2 files changed, 72 insertions(+), 92 deletions(-) diff --git a/main.py b/main.py index a8e554f..f3987d0 100755 --- a/main.py +++ b/main.py @@ -250,7 +250,12 @@ class bc(object): if self.operating_system == 'linux': if self.method == '-e': self.method = '-E' - self.content = subprocess.check_output(['lft', '-S', '-n', self.method, self.destination_ip]) + try: + self.content = subprocess.check_output(['lft', '-S', '-n', self.method, self.destination_ip]) + # support for older python versions (<2.7) that don't support subprocess.check_output + except: + a = subprocess.Popen(['lft', '-S', '-n', self.method, self.destination_ip], stdout=subprocess.PIPE) + self.content = a.stdout.read() self.attempts += 1 if self.options.debug == True: @@ -290,7 +295,7 @@ class bc(object): time.sleep(2) self.lft() - if 'udp no reply from target] Use -VV to see packets.' in output[-1]: + if 'udp no reply from target] Use -VV to see packets.' in output[-1] and len(output) > 5: if self.options.debug == True: print 'Trace ended with results \n' return diff --git a/web/index.py b/web/index.py index 6f8ac88..da8c5b5 100755 --- a/web/index.py +++ b/web/index.py @@ -1,44 +1,52 @@ -#!/usr/local/bin/python -# -*- 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) -""" +#new index.py +# -*- coding: ISO-8859-1 -*- +from lxml import etree + from xml.dom.minidom import parseString # extract data from a xml file -file = open('data.xml','r') -data = file.read() -file.close() -dom = parseString(data) -xmlTag = dom.getElementsByTagName('travel')[0].toxml() -xmlData= xmlTag.replace('','').replace('','') -xmlHost = dom.getElementsByTagName('host')[0].toxml() -xmlIP = dom.getElementsByTagName('hop_ip')[0].toxml() -xmlLongitude = dom.getElementsByTagName('longitude')[0].toxml() -xmlLatitude = dom.getElementsByTagName('latitude')[0].toxml() -xmlCity = dom.getElementsByTagName('city')[0].toxml() -xmlCountry = dom.getElementsByTagName('country')[0].toxml() -xmlServerName = dom.getElementsByTagName('server_name')[0].toxml() -xmlMeta = dom.getElementsByTagName('meta')[0].toxml() - -# parse XML inputs -xmlLongitude = xmlLongitude.replace('','') -xmlLatitude = xmlLatitude.replace('','') -xmlLongitude = xmlLongitude.replace('','') -xmlLatitude = xmlLatitude.replace('','') -xmlMeta = xmlMeta.replace('','') -xmlMeta = xmlMeta.replace('','') -xmlHost = xmlHost.replace('','') -xmlHost = xmlHost.replace('','') -xmlIP = xmlIP.replace('','') -xmlIP = xmlIP.replace('','') -xmlCity = xmlCity.replace('','') -xmlCity = xmlCity.replace('','') -xmlCountry = xmlCountry.replace('','') -xmlCountry = xmlCountry.replace('','') -xmlServerName = xmlServerName.replace('','') -xmlServerName = xmlServerName.replace('','') +f = open('data.xml', 'r') +f2 = open('data.xml', 'r') +xml = etree.parse(f) + +data = f2.read() +dom = parseString(data.encode('utf-8')) + +f.close() +f2.close() + + + + +n_hops = dom.getElementsByTagName('hop')[-1].toxml().replace('', '').replace('','').replace('','') + asn = hop.getElementsByTagName('asn')[0].toxml().replace('','').replace('','') + hop_ip = hop.getElementsByTagName('hop_ip')[0].toxml().replace('','').replace('','') + longitude = hop.getElementsByTagName('longitude')[0].toxml().replace('','').replace('','') + latitude = hop.getElementsByTagName('latitude')[0].toxml().replace('','').replace('','') + + point = """ L.marker(["""+latitude+""", """+longitude+"""]).addTo(map) + .bindPopup(""""+server_name+"""
"""+hop_ip+"""
"""+asn+"""
").openPopup(); """ + + latlong = [float(latitude.encode('utf-8')), float(longitude.encode('utf-8'))] + geoarray.append(latlong) + + hoplist.append(point) + + b = b+point + + +test = open('test.html','w') + output = """ @@ -48,61 +56,28 @@ output = """ - +
- - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Host:"""+xmlHost+"""
IP:"""+xmlIP+"""
Coordinates:"""+xmlLongitude+""" : """+xmlLatitude+"""
Server name:"""+xmlServerName+"""
Country:"""+xmlCountry+"""
City:"""+xmlCity+"""
Metadata:"""+xmlMeta+"""
-
-
-
+
""" + +test.write(output) +test.close \ No newline at end of file