Пример #1
0
def trans_atlantic_traceroute(iface, ipdst, limit=64, m=2):
    answers = traceroute(iface, ipdst, limit)
    n = len(answers)
    trans_atlantic_nodes = []
    for i, hop in enumerate(answers):
        if i < (n - 1):
            j = i + 1
            next_hop = answers[j]
            rtt1, rtt2 = hop[1], next_hop[1]
            R = (rtt1 + rtt2) / 2  # promedio los rtt consecutivos
            d = desvio_standar(rtt1, rtt2)
            r = rtt1 + rtt2
            if r > R + m * d:
                trans_atlantic_nodes.append(next_hop)
        else:
            break
    return trans_atlantic_nodes
def go():
    global ttl
    ip_pattern = r'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
    if re.match(ip_pattern, dest_ip_entry.get()) is None:
        showerror(title='error', message='invaild ip address')
    else:
        r = traceroute(dest_ip_entry.get(), ttl)
        if ttl == 1:
            result_text.delete(1.0, END)
            result_text.insert(END, 'ttl\taddress\t\ttype\tcode\t1\t2\t3\n')
        result_text.insert(END, r)
        if '\t3\t3' in r:
            ttl = 1
            next_svar.set('traceroute')
            showinfo(title='done', message='traceroute finished')
        else:
            ttl += 1
            next_svar.set('next')
Пример #3
0
def go():
    global ttl
    ip_pattern = r'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
    if re.match(ip_pattern, dest_ip_entry.get()) is None:
        showerror(title='error', message='invaild ip address')
    else:
        r = traceroute(dest_ip_entry.get(), ttl)
        if ttl == 1:
            result_text.delete(1.0, END)
            result_text.insert(END, 'ttl\taddress\t\ttype\tcode\t1\t2\t3\n')
        result_text.insert(END, r)
        if '\t3\t3' in r:
            ttl = 1
            next_svar.set('traceroute')
            showinfo(title='done', message='traceroute finished')
        else:
            ttl += 1
            next_svar.set('next')
Пример #4
0
import traceroute

traceroute.traceroute("172.31.13.98")
Пример #5
0
def main(args):

    # Establish IPv4 address
    if not is_valid_ip(args.host):
        if is_valid_hostname(args.host):
            args.host = nslookup(args.host)
        else:
            raise IOError(f'Could not parse argument \'host\': {args.host}')
    print(args.host)

    # Trace the route
    if True: # FIXME
        traceroute_output = traceroute(args.host)
        ips = [l.ip for l in traceroute_output if l.ip is not None]
    else:
        ips = [
            '192.168.1.1',
            '50.53.152.1',
            '50.46.177.146',
            '50.46.176.48',
            '204.194.220.5',
            '107.191.236.64',
            '206.81.80.112',
            '202.158.194.120',
            '113.197.15.146',
            '113.197.15.12',
            '113.197.15.11',
            '138.44.161.3',
            '150.203.201.5',
            '150.203.201.33',
            '130.56.66.152'
        ]
    if True: # FIXME
        from pprint import pprint
        pprint(ips)

    # Write to map
    print('Generating map:')
    map_ = Map()
    coords_prev = None
    connect = []
    from map import Color # FIXME
    for ip in ips:
        whois_output = whois(ip)
        coords = get_most_precise_location(whois_output)
        if coords is None:
            print('-->', 'No location found. Skipping', ip)
            continue
        if coords == coords_prev:
            print('-->', 'Same location. Omitting', ip)
            continue
        map_.add_route_point(coords, color=Color.blue)
        # if coords_prev is not None:
        #     map_.add_route_segment(coords_prev, coords)
        connect.append(coords)
        coords_prev = coords
    for i in range(len(connect) - 1):
        map_.add_route_segment(connect[i], connect[i + 1])
    map_.save()
    exit(0)

    whois_output = whois(args.host)
    coords_endpoint = get_most_precise_location(whois_output)
    print(f'Endpoint location: {coords_endpoint}')
Пример #6
0
def proxy_test(target, max_ttl, timeout, verbose=None, \
               n_https_traces=DEFAULT_HTTPS_TRACES,    \
               n_http_traces=DEFAULT_HTTP_TRACES):
    """
    Tests if the target is running behind a proxy.
    Does this by comparing the traceroute traces of a set of HTTPS and HTTP SYN
    packets.
    Returns None if the target was unreachable or a tuple if it was reachable.
    The tuple (has_proxy, probability) gives if a proxy is running and an
    estimation of the probability that the proxy really exist (false positive
    are possible because of path load-balancing).
    """

    def path_IPs(path):
        """
        Returns the tuple of routers IPs from a traceroute trace.
        Returns a tuple instead of a list as lists are not hashable and can not
        be used in sets.
        """
        return tuple(None if resp == None else resp.src for _, resp in path)

    target_ip = socket.gethostbyname(target)

    # Probes the target with HTTPS SYNs to gather some (probably) non-proxied
    # paths.

    paths = []
    for _ in xrange(n_https_traces):
        path = traceroute(
            target_ip, max_ttl, timeout, dport=443, verbose=verbose
        )

        # Ignores unreachable traces. Only remember the response source IPs.
        if path != None:
            paths.append(path_IPs(path))

    n_https_paths = len(paths)
    if n_https_paths == 0:
        return None

    # Probes the target with HTTP SYNs. If a traced path equals one previously
    # probed path, considers that there is no proxy.

    unique_paths = set(paths)

    n_http_paths = 0
    for _ in xrange(n_http_traces):
        path = traceroute(
            target_ip, max_ttl, timeout, dport=80, verbose=verbose
        )

        # Ignores unreachable traces. Only remember the response source IPs.
        if path != None:
            if path_IPs(path) in unique_paths:
                return (False, 0)
            else:
                n_http_paths += 1

    # No HTTP path is the same as any HTTPS one. HTTP is probably running behind
    # a proxy. Computes the probability that no corresponding path have been
    # found because of something else that a proxy (load-balancing ...).

    # For each probed HTTPS path, computes how many paths differs. Sum these
    # values.
    # Complexity : O(n log n).

    def n_differ_group(group):
        n = ilen(group)
        return n * (n_https_paths - n)

    paths.sort()
    n_differ = sum(n_differ_group(group) for _, group in groupby(paths))

    # Deduces an estimation of the probability of two given paths to differ.
    prob_differ = float(n_differ) / float(n_https_paths * (n_https_paths - 1))

    # print "P: {0} - HTTPS: {1} - HTTP: {2}".format(
    #    prob_differ, n_https_paths, n_http_paths
    # )

    # Uses this estimation to compute the probability that our result is a
    # product of a proxy and not of routing dynamics.
    prob_result = 1 - prob_differ**(n_https_paths * n_http_paths)

    return (True, prob_result)
Пример #7
0
import sys
import os
from traceroute import traceroute
import datetime

if len(sys.argv) < 5:
  print "Error: faltan parametros. Uso: rtt_traceroute.py interfaz max_hops iteraciones archivoEntrada"
  exit(1)
	
interface = sys.argv[1]
max_hops = int(sys.argv[2])
it = int(sys.argv[3])
#levanto datos de destinos
with open(sys.argv[4]) as f:
 lines = f.readlines()

for line in lines:
 line = line.replace("\n", "")
 (dst, dns, ip) = line.split("\t")
 dtime = datetime.datetime.now().time()
 with os.fdopen(os.open('rtt' + dst + '_' + str(dtime.hour) + 'h_' + str(dtime.minute) + 'm.txt', os.O_WRONLY | os.O_CREAT, 0600), 'w') as handle:
 #fd = os.open('rtt' + dst + '_' + str(dtime.hour) + 'h_' + str(dtime.minute) + 'm.txt', os.O_RDWR, int("0600", 8))
 #fs = os.fdopen(fd, 'w')
  for i in range (0, it):
   answers = traceroute(interface, ip, max_hops)
   rtt = answers[len(answers)-1][1]
   handle.write('%d\t%d\n' % (i,rtt*1000))
   #print('%d\t%d\n' % (i,rtt*1000))
  #fs.close()
Пример #8
0
 def trace_site(site):
     trace = traceroute(
         site, max_ttl, timeout, verbose=verbose,
         tcp_options=[('MSS', INIT_MSS)]
     )
     return site, trace
Пример #9
0
        command = connectionSocket.recv(64)
        print "Command is:", command
        if command == 'results':
            print ' Results: '
            data = connectionSocket.recv(2048)
            print "Recieve Data :", data
            array = data.split(",")
            ServerIP = array[0]
            Pings = array[1]
            print 'EndServerIP:', ServerIP
            print 'Pings:', Pings

            max_pings = int(Pings)

            RTT = ping(ServerIP, max_pings)
            hops = traceroute(ServerIP)
            print "The results : RTT = ", str(RTT), " hops = ", str(hops)
            #Send Results
            Send_data = str(RTT) + "," + str(hops)
            connectionSocket.send(Send_data)

        elif command == 'file':
            print 'File : '
            url = connectionSocket.recv(512)

            testfile = urllib.URLopener()
            testfile.retrieve(url, 'file')

            f = open('file', 'rb')
            l = f.read(1024)
            while (l):
Пример #10
0
def compute_trace(source, destination):
    logging.info("Tracerouting: %s" % destination)
    output = traceroute(source, str(destination))
    return output