Note that there are some explanatory texts on larger screens.

plurals
  1. POTraceroute script returning duplicated results
    primarykey
    data
    text
    <p>I have a script which performs the following tasks: Read from file to get IP address Perform Traceroute Store results of hop count, host name and IP address to a timestamped file.</p> <p>Problem is, the results shows duplicated hope counts which makes the hop count more when I compare to normal traceroute results.</p> <p>Here is part of the script:</p> <pre><code>import socket, sys, os, ipList from ipList import ip4 from datetime import datetime icmp = socket.getprotobyname('icmp') udp = socket.getprotobyname('udp') port = 33434 max_hops = 30 ttl = 1 curr_addr = None curr_name = None def main(ips): FORMAT = '%Y%m%d%H%M' for ip in ips: path = ip+'.txt' new_path = 'results/%s_%s' % (datetime.now().strftime(FORMAT), path) dest_addr_v4 = ip m(dest_addr_v4, port, ttl, max_hops, new_path) def writeFile(p, a): # with open(new_path, 'a') as result: result = open(p, 'a') result.write(a) result.close() def create_sockets(): recv_s = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp) send_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp) send_s.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl) return recv_s, send_s def m(ip, p, t, mh, path): while True: recv_s, send_s = create_sockets() recv_s.bind(("", p)) send_s.sendto("", (ip, p)) try: _, curr_addr = recv_s.recvfrom(512) curr_addr = curr_addr[0] try: curr_name = socket.gethostbyaddr(curr_addr)[0] except socket.error: curr_name = curr_addr except socket.error: pass finally: send_s.close() recv_s.close() if curr_addr is not None: curr_host = "%s (%s)" % (curr_name, curr_addr) else: curr_host = "*" r = "%d\t%s\n" % (t, curr_host) if t &lt;= mh: writeFile(path, r) t += 1 if curr_addr == ip or t &gt; mh: print "Reached end of max hop or reached Destination" return ipv4List = ip4() main(ipv4List) </code></pre> <p>I have file with list of IP address and I'm trying to measure paths so ideally I would want the results to be as accurate as possible. At the moment the results I'm getting is not correct, I'm assuming because it is sending multiple UPD packets and getting ICMPs in return.</p> <p>Is there a way to fine tune this script please?</p> <p>Edit: Hi, thanks for repyling. I'm very sorry I forgot to add the results.</p> <p>Here are the results I mentioned above:</p> <pre><code>1 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 2 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 3 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 4 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 5 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 6 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 7 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 8 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 9 clifton3-gw-t2-1.emman.net (194.82.121.13) 10 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 11 so-0-0-0.lond-sbr1.ja.net (146.97.42.53) 12 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 13 ae13.londtn-sbr1.ja.net (146.97.33.134) 14 prs-bb2-link.telia.net (80.91.246.177) 15 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 16 vlan907-an-cat6k-ts2-r1.starhub.net.sg (203.118.3.217) 17 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 18 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 19 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 20 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 21 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 22 mailhost.lboro.ac.uk (158.125.160.55) 23 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 24 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 25 pinger-j2.ant.isi.edu (203.178.148.19) 26 mailhost.lboro.ac.uk (158.125.160.55) 27 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) 28 pinger6.netsec.colostate.edu (129.82.138.44) 29 mailhost.lboro.ac.uk (158.125.160.55) 30 router.comp-sci-staff-dhcp.hsrp.lut.ac.uk (158.125.103.1) </code></pre> <p>As you can see, everything is duplicated, and I suspect because I set the max_hop as 30 it would have continued like this beyond if increased. This doesn't show if it reached the destination IP:203.175.174.10 from the first entry of my IPlist file.</p> <p>I would really appreciate any sort of input and advise. Sorry if my post is not up to standard.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload