Browse Source

added AS database, added long+lat variables, added hostname variable, fixed some stuff

pull/3/head
rscmbbng 11 years ago
parent
commit
62ff6f2b3f
  1. 93
      main.py
  2. BIN
      web/.DS_Store
  3. 0
      web/__init__.py
  4. BIN
      web/__init__.pyc
  5. 0
      web/images/WM1.svg
  6. 22
      web/index.py
  7. 12
      xml_exporter.py

93
main.py

@ -41,10 +41,12 @@ class bc(object):
self.url = "" self.url = ""
self.old_url = "" self.old_url = ""
self.ip = "" self.ip = ""
self.longitude =""
self.latitude = ""
self.hop_host_name ="" self.hop_host_name =""
self.city = "" self.city = ""
self.country = "" self.country = ""
self.routes = "" self.server_name = ""
def set_options(self, options): def set_options(self, options):
""" """
@ -219,7 +221,8 @@ class bc(object):
Use LFT to traceroute objetives and pass data to webserver Use LFT to traceroute objetives and pass data to webserver
''' '''
# Set database (GeoLiteCity) # Set database (GeoLiteCity)
self.geoip= pygeoip.GeoIP('GeoLiteCity.dat') self.geoip = pygeoip.GeoIP('GeoLiteCity.dat')
self.geoasn = pygeoip.GeoIP('GeoIPASNum.dat')
print '='*45 + "\n", "Current target:\n" + '='*45 + "\n" print '='*45 + "\n", "Current target:\n" + '='*45 + "\n"
print "URL:", self.url[0], "\n" print "URL:", self.url[0], "\n"
@ -248,12 +251,12 @@ class bc(object):
# using udp # using udp
try: try:
print "Method: udp\n" print "Method: udp\n"
a = subprocess.Popen(['lft', '-S', '-n', '-u', url_ip], stdout=subprocess.PIPE) a = subprocess.Popen(['lft', '-S', '-n', '-e', url_ip], stdout=subprocess.PIPE)
# using tcp # using tcp
except: except:
try: try:
print "Method: tcp\n" print "Method: tcp\n"
a = subprocess.Popen(['lft', '-S', '-n', '-E', url_ip], stdout=subprocess.PIPE) a = subprocess.Popen(['lft', '-S', '-n', '-e', url_ip], stdout=subprocess.PIPE)
except: except:
print "Error: network is not responding correctly. Aborting...\n" print "Error: network is not responding correctly. Aborting...\n"
sys.exit(2) sys.exit(2)
@ -270,30 +273,45 @@ class bc(object):
for ip in parts: for ip in parts:
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):
record = self.geoip.record_by_addr(ip) record = self.geoip.record_by_addr(ip)
try:
asn = self.geoasn.org_by_addr(ip)
except:
asn = 'nothing'
#print record #print record
try: try:
self.hop_host_name = socket.gethostbyaddr(ip)[0] self.hop_host_name = socket.gethostbyaddr(ip)[0]
except: except:
self.hop_host_name = 'No hostname' self.hop_host_name = 'No hostname'
try:
longitude = str(record['longitude'])
self.longitude = longitude
latitude = str(record['latitude'])
self.latitude = latitude
except:
self.longitude = '-'
self.latitude = '-'
try: try:
if record.has_key('country_name') and record['city'] is not '': if record.has_key('country_name') and record['city'] is not '':
country = record['country_name'] country = record['country_name']
city = record['city'] city = record['city']
print "Trace:", count, "->", ip, "->", city, "->", country, "->", self.hop_host_name
print "Trace:", count, "->", ip, "->", city, "->", country, "->", self.hop_host_name, asn
count+=1 count+=1
self.city = city self.city = city
self.country = country self.country = country
self.routes = "Trace:", count, "->", ip, "->", city, "->", country self.server_name = self.hop_host_name
elif record.has_key('country_name'): elif record.has_key('country_name'):
country = record['country_name'] country = record['country_name']
print "Trace:", count, "->", ip, "->", country, "->", self.hop_host_name print "Trace:", count, "->", ip, "->", country, "->", self.hop_host_name, asn
self.country = country self.country = country
self.routes = "Trace:", count, "->", ip, "->", country self.server_name = self.hop_host_name
count+=1 count+=1
except: except:
print "Trace:", count, "->", "Not allowed" print "Trace:", count, "->", "Not allowed"
count+=1 count+=1
if self.options.debug == True:
logfile.close() logfile.close()
self.old_url = url self.old_url = url
@ -329,7 +347,28 @@ class bc(object):
f_in.close() f_in.close()
os.remove('GeoLiteCity.gz') os.remove('GeoLiteCity.gz')
print "Database: GeoLiteCity\n"
maxmind_asn = 'http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz'
# Download, extract and set geoipdatabase
if not os.path.exists('GeoIPASNum.dat'):
import urllib, gzip
geo_db_path = '/'
try:
print "Downloading GeoIP ASN database...\n"
if self.options.debug == True:
print "Fetching from:", maxmind_asn
urllib.urlretrieve(maxmind,
'GeoIPASNum.gz')
except:
print("[Error] - Something wrong fetching GeoIP maps from the Internet. Aborting..."), "\n"
sys.exit(2)
f_in = gzip.open('GeoIPASNum.gz', 'rb')
f_out = open('GeoIPASNum.dat', 'wb')
f_out.write(f_in.read())
f_in.close()
os.remove('GeoIPASNum.gz')
print "Database: GeoIPASNum \n"
def run(self, opts=None): def run(self, opts=None):
""" """
@ -369,12 +408,26 @@ class bc(object):
# run traceroutes # run traceroutes
match_ip = self.url[0].strip('http://').strip(':8080') 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): 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 pass
else: 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.") traces = self.try_running(self.traces, "\nInternal error tracerouting.")
#xml_results = xml_reporting(self)
#xml_results.print_xml_results('data.xml')
# export data to XML # export data to XML
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
print '='*45 + "\n" print '='*45 + "\n"
print "Status: Waiting for new urls ...\n" print "Status: Waiting for new urls ...\n"
@ -385,11 +438,25 @@ class bc(object):
match_ip = url.strip('http://').strip(':8080') match_ip = url.strip('http://').strip(':8080')
if url != self.old_url: 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): 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 pass
else: 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.") traces = self.try_running(self.traces, "\nInternal error tracerouting.")
#xml_results = xml_reporting(self) xml_results = xml_reporting(self)
#xml_results.print_xml_results('data.xml') xml_results.print_xml_results('data.xml')
if __name__ == "__main__": if __name__ == "__main__":

BIN
web/.DS_Store

Binary file not shown.

0
web/__init__.py

BIN
web/__init__.pyc

Binary file not shown.

0
web/images/WM1.svg

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

22
web/index.py

@ -14,7 +14,11 @@ xmlTag = dom.getElementsByTagName('travel')[0].toxml()
xmlData= xmlTag.replace('<travel>','').replace('</travel>','') xmlData= xmlTag.replace('<travel>','').replace('</travel>','')
xmlHost = dom.getElementsByTagName('host')[0].toxml() xmlHost = dom.getElementsByTagName('host')[0].toxml()
xmlIP = dom.getElementsByTagName('ip')[0].toxml() xmlIP = dom.getElementsByTagName('ip')[0].toxml()
xmlRoutes = dom.getElementsByTagName('routes')[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() xmlMeta = dom.getElementsByTagName('meta')[0].toxml()
output = """ output = """
@ -41,8 +45,20 @@ output = """
<td>"""+xmlIP+"""</td> <td>"""+xmlIP+"""</td>
</tr> </tr>
<tr> <tr>
<td><b>Packages Route:</b></td> <td><b>Coordinates:</b></td>
<td>"""+xmlRoutes+"""</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>
<tr> <tr>
<td><b>Metadata:</b></td> <td><b>Metadata:</b></td>

12
xml_exporter.py

@ -18,12 +18,20 @@ class xml_reporting(object):
root = ET.Element("travel") root = ET.Element("travel")
host = ET.SubElement(root, "host") host = ET.SubElement(root, "host")
ip = ET.SubElement(root, "ip") ip = ET.SubElement(root, "ip")
routes = ET.SubElement(root, "routes") 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") meta = ET.SubElement(root, "meta")
host.text = self.instance.url[0] host.text = self.instance.url[0]
ip.text = self.instance.ip ip.text = self.instance.ip
routes.text = self.instance.routes longitude.text = self.instance.longitude
latitude.text = self.instance.latitude
city.text = self.instance.city
country.text = self.instance.country
server_name.text = self.instance.server_name
meta.text = "Connect here XML metadata" meta.text = "Connect here XML metadata"
tree = ET.ElementTree(root) tree = ET.ElementTree(root)

Loading…
Cancel
Save