OrphanSec

Traceroute.py

Apr 20th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import socket,sys
  4. def main(dest):
  5.       ttl = 1
  6.       max = 30
  7.       dest = socket.gethostbyname(dest)
  8.       icmp = socket.getprotobyname('icmp')  
  9.       port = 12345
  10.       while True:
  11.             incoming = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
  12.             outgoing = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  13.             outgoing.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
  14.             incoming.bind(("", port))
  15.             outgoing.sendto("", (dest, port))
  16.             NULL, address = incoming.recvfrom(1024)
  17.             address = address[0]
  18.             fuckery = socket.gethostbyaddr(address)[0]
  19.             if address is not None:
  20.                   current = '{0} {1}'.format(fuckery,address)
  21.             else:
  22.                   current = '*'
  23.             print '{0}  {1}'.format(ttl,current)
  24.             ttl += 1
  25.             if address == dest or ttl > max:
  26.                   break
  27.            
  28.  
  29. if __name__ == '__main__':
  30.       main(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment