Exemplo n.º 1
0
def track(ips):
    sources_file = open('sources.json').read()

    sources = json.loads(sources_file)
    source_template = sources['LO']['url']

    country_hops = dict.fromkeys(latinamerica, {})

    #ACA CAMBIAS EL 4 SI ES QUE CORRE MAS RAPIDO EN TU PC
    for i in range(10):
        for country in ips.keys():
            ip = ips[country][0]
            sources['LO']['url'] = source_template.replace('_IP_ADDRESS_', ip)
#            pprint.pprint(sources, indent=4)
            t = Traceroute(ip_address=ip,
                           source=sources['LO'],
                           country='LO',
                           timeout=900)
#            t.ip_address = ip
            print 'Starting'
            hops = t.traceroute()
            print 'Finished'

            #write it to some structure
            country_hops[country][ip] = hops

            #delete it from ip list
            ips[country].remove(ip)

            pprint.pprint(hops)

    #replace original file with deleted rows
    with open('ips.json', 'w') as ipsjson:
        ipsjson.write(json.dumps(ips, indent=4))

    #write file with obtained hop results
    with open('results.json', 'w') as ipsjson:
        ipsjson.write(json.dumps(country_hops, indent=4))
import sys
from traceroute import Traceroute

tracefile = open(str(sys.argv[1]),'r')

traceline = tracefile.readlines()
router_list = []
trace_out = open("trace_output.txt",'a')
for line in traceline:
	entry = line.split(',')
	d_name = str(entry[0])
	ttl_val = int(entry[1].rstrip())
	traceroute = Traceroute(d_name)
	print d_name
	try :
		hops = traceroute.traceroute()	
		total_hops = len(hops)
		if total_hops < ttl_val :
			out_hop = hops[total_hops-1]
			router_list.append(hops[total_hops-1])
		else :
			router_list.append(hops[ttl_val-1])
			out_hop = hops[ttl_val-1]

		output = out_hop['ip_address'] + '\n'
		trace_out.write(output)
	except:
		continue


print router_list
Exemplo n.º 3
0
from traceroute import Traceroute
trt = Traceroute("8.8.8.8", source="sources/sources.json")
hops = trt.traceroute()

for h in hops:
    print "Hop: ", h