Browse Source

now tries subprocess.popen if subprocess.check_output fails. added map drawing feature in index.py

pull/3/head
rscmbbng 11 years ago
parent
commit
437772b205
  1. 9
      main.py
  2. 155
      web/index.py

9
main.py

@ -250,7 +250,12 @@ class bc(object):
if self.operating_system == 'linux': if self.operating_system == 'linux':
if self.method == '-e': if self.method == '-e':
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 self.attempts += 1
if self.options.debug == True: if self.options.debug == True:
@ -290,7 +295,7 @@ class bc(object):
time.sleep(2) time.sleep(2)
self.lft() 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: if self.options.debug == True:
print 'Trace ended with results \n' print 'Trace ended with results \n'
return return

155
web/index.py

@ -1,44 +1,52 @@
#!/usr/local/bin/python #new index.py
# -*- coding: iso-8859-15 -*- # -*- coding: ISO-8859-1 -*-
""" 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
# extract data from a xml file # extract data from a xml file
file = open('data.xml','r') f = open('data.xml', 'r')
data = file.read() f2 = open('data.xml', 'r')
file.close() xml = etree.parse(f)
dom = parseString(data)
xmlTag = dom.getElementsByTagName('travel')[0].toxml() data = f2.read()
xmlData= xmlTag.replace('<travel>','').replace('</travel>','') dom = parseString(data.encode('utf-8'))
xmlHost = dom.getElementsByTagName('host')[0].toxml()
xmlIP = dom.getElementsByTagName('hop_ip')[0].toxml() f.close()
xmlLongitude = dom.getElementsByTagName('longitude')[0].toxml() f2.close()
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() n_hops = dom.getElementsByTagName('hop')[-1].toxml().replace('<hop>', '').replace('</hop','')
# parse XML inputs hoplist = []
xmlLongitude = xmlLongitude.replace('<longitude>','') geoarray = []
xmlLatitude = xmlLatitude.replace('<latitude>','') latlong= []
xmlLongitude = xmlLongitude.replace('</longitude>','')
xmlLatitude = xmlLatitude.replace('</latitude>','') b = ''
xmlMeta = xmlMeta.replace('<meta>','')
xmlMeta = xmlMeta.replace('</meta>','') for counter in range(1, int(xml.findall('hop')[-1].text)+1):
xmlHost = xmlHost.replace('<host>','') hop = parseString(dom.getElementsByTagName('hop')[counter].toxml().encode('utf-8'))
xmlHost = xmlHost.replace('</host>','') server_name = hop.getElementsByTagName('server_name')[0].toxml().replace('<server_name>','').replace('</server_name>','')
xmlIP = xmlIP.replace('<ip>','') asn = hop.getElementsByTagName('asn')[0].toxml().replace('<asn>','').replace('</asn>','')
xmlIP = xmlIP.replace('</ip>','') hop_ip = hop.getElementsByTagName('hop_ip')[0].toxml().replace('<hop_ip>','').replace('</hop_ip>','')
xmlCity = xmlCity.replace('<city>','') longitude = hop.getElementsByTagName('longitude')[0].toxml().replace('<longitude>','').replace('</longitude>','')
xmlCity = xmlCity.replace('</city>','') latitude = hop.getElementsByTagName('latitude')[0].toxml().replace('<latitude>','').replace('</latitude>','')
xmlCountry = xmlCountry.replace('<country>','')
xmlCountry = xmlCountry.replace('</country>','') point = """ L.marker(["""+latitude+""", """+longitude+"""]).addTo(map)
xmlServerName = xmlServerName.replace('<server_name>','') .bindPopup("<b>"""+server_name+"""</b><br />"""+hop_ip+"""<br />"""+asn+"""<br />").openPopup(); """
xmlServerName = xmlServerName.replace('</server_name>','')
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 = """ output = """
<html> <html>
@ -48,61 +56,28 @@ output = """
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<script src="js/leaflet/leaflet.js"></script> <script src="js/leaflet/leaflet.js"></script>
<!--<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>--> <!--<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>-->
<meta http-equiv="refresh" content="3"> <script type="text/javascript">
window.onload = function () {
var map = L.map('map').setView(["""+latitude+""", """+longitude+"""], 2);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
"""+b+"""
var latlong = """+str(geoarray)+"""
var polyline = L.polyline(latlong, {color: 'red'}).addTo(map);
};
</script>
</head> </head>
<body> <body>
<center> <center>
<table> <td><center><div id="map" style="width: 1000px; height: 800px"></div></center></td>
<tr>
<td><center><div id="map" style="width: 600px; height: 400px"></div></center></td>
<script>
var map = L.map('map').setView(["""+xmlLatitude+""", """+xmlLongitude+"""], 14);
L.marker(["""+xmlLatitude+""", """+xmlLongitude+"""]).addTo(map)
.bindPopup("<b>"""+xmlMeta+"""</b><br />").openPopup();
var popup = L.popup();
</script>
</tr>
<tr>
<td>
<center>
<table border="1">
<tr>
<td><b>Host:</b></td>
<td>"""+xmlHost+"""</td>
</tr>
<tr>
<td><b>IP:</b></td>
<td>"""+xmlIP+"""</td>
</tr>
<tr>
<td><b>Coordinates:</b></td>
<td>"""+xmlLongitude+""" : """+xmlLatitude+"""</td>
</tr>
<tr>
<td><b>Server name:</b></td>
<td>"""+xmlServerName+"""</td>
</tr>
<tr>
<td><b>Country:</b></td>
<td>"""+xmlCountry+"""</td>
</tr>
<tr>
<td><b>City:</b></td>
<td>"""+xmlCity+"""</td>
</tr>
<tr>
<td><b>Metadata:</b></td>
<td>"""+xmlMeta+"""</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
</center>
</body> </body>
</html> </html>
""" """
test.write(output)
test.close
Loading…
Cancel
Save