コード例 #1
0
    def traceroute(self, host, hops=8):
        """traceroute -m <hops> <host>"""
        from traceroute import Traceroute
        result = dict()
        # Инициализация класса
        try:
            traceroute = Traceroute(host = host, hops = hops)
            traceroute.hops = hops or 8

            (retcode, out) = traceroute.traceroute_host()
            cmd_result = out.split("\n")

            if retcode == 0:
                tracerouted = True
            else:
                tracerouted = False

            out = list()
            for s in cmd_result:
                out.append((s, ))

            result['status'] = True
            result['result'] = tracerouted
            result['data'] = out
        except Exception as e:
            result['status'] = False
            result['data'] = (('error:', e.message), )
            return result

        return result
コード例 #2
0
ファイル: georoute.py プロジェクト: ashenm/georoute
    def __init__(self, hostname):

        self.engine = Map()
        self.destination = gethostbyname(hostname)
        self.tracer = Traceroute(self.destination, self.engine)

        self.engine.markers.FILL = 'OrangeRed3'
        self.engine.markers.LFILL = 'OrangeRed4'
        self.tracer.CALLBACK = self.engine.clean
        self.tracer.SEPERATOR = ''
コード例 #3
0
ファイル: tmap.py プロジェクト: asdil12/pytracert
		def _trace_thread(target, cb):
			self.tr_button.set_label('Stop')
			self.tb.set_text('')
			try:
				print "thread run"
				t = Traceroute()
				t.set_callback(cb)
				self.osm.gps_clear()
				t.run(target)
				print "thread exit"
			finally:
				self.tr_button.set_label('Trace')
コード例 #4
0
ファイル: agent.py プロジェクト: jianghengle/traceroute-map
 def start(self):
     try:
         self.parseTarget()
         traceroute = Traceroute(self.target, self)
         Agent.traceroutes.append(traceroute)
         self.dispatch()
     except:
         self.close()
コード例 #5
0
ファイル: tracer.py プロジェクト: wocoburguesa/redes-tracer
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))
コード例 #6
0
 def _trace_thread(target, cb):
     self.tr_button.set_label('Stop')
     self.tb.set_text('')
     try:
         print "thread run"
         t = Traceroute()
         t.set_callback(cb)
         self.osm.gps_clear()
         t.run(target)
         print "thread exit"
     finally:
         self.tr_button.set_label('Trace')
コード例 #7
0
ファイル: tcmd.py プロジェクト: asdil12/pytracert
#!/usr/bin/python2

from traceroute import Traceroute
import georesolve
import sys


def print_callback(ttl, payload):
    if payload:
        curr_host = "%(hostname)s (%(ip)s)" % payload
        print "%d\t%s" % (ttl, curr_host)
        print "\t",
        print georesolve.lookup(**payload)
    else:
        print "%d\t*" % ttl


if __name__ == "__main__":
    t = Traceroute(timeout=1)
    t.set_callback(print_callback)
    t.run(target=sys.argv[1])
コード例 #8
0
import os
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

コード例 #9
0
ファイル: example.py プロジェクト: dropmeaword/traceroute
from traceroute import Traceroute
trt = Traceroute("8.8.8.8", source="sources/sources.json")
hops = trt.traceroute()

for h in hops:
    print "Hop: ", h
コード例 #10
0
ファイル: tcmd.py プロジェクト: asdil12/pytracert
#!/usr/bin/python2

from traceroute import Traceroute
import georesolve
import sys

def print_callback(ttl, payload):
	if payload:
		curr_host = "%(hostname)s (%(ip)s)" % payload
		print "%d\t%s" % (ttl, curr_host)
		print "\t",
		print georesolve.lookup(**payload)
	else:
		print "%d\t*" % ttl

if __name__ == "__main__":
	t = Traceroute(timeout=1)
	t.set_callback(print_callback)
	t.run(target=sys.argv[1])
コード例 #11
0
import argparse
import socket

from traceroute import Traceroute
from icmp import IcmpPack

if __name__ == '__main__':
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('host', type=str)
    args = arg_parser.parse_args()
    # try:
    traceroute = Traceroute(args.host)
    trace_result = traceroute.make_trace()
    for count, el in enumerate(trace_result, start=1):
        print(f'{count}. {el}')
    # except socket.gaierror:
    #     print(f'{args.host} is invalid')
    # pack = IcmpPack(8, 0)
    # print(len(pack.pack_icmp()))
コード例 #12
0
from utilities import get_args, create_directories
from rrd import create, update
from traceroute import Traceroute
import pathlib
import argparse as ap

parser = ap.ArgumentParser()
parser.add_argument('target')
args = parser.parse_args()

directory = '/var/www/html/django'  # TODO: Remove hardcoded location.
target = args.target

args = get_args(directory, target)
rrd_dir, graph_dir = create_directories(args, target)
tr = Traceroute(target, rrd_dir, graph_dir)
exists = pathlib.Path(tr.rrd).exists()

exists or create(tr, args)
update(tr)