4

Hi i am trying to run this traceroute code in windows 7 but the python script does not receive the replies from the router, this script works in linux and just timeout in windows. in wireshark i can see that the ping requests are being sent and the routers are replying however the script does not register them, can some one help?

Edit: Works in window xp but no luck in windows 7!!!

#!/usr/bin/python

import socket

def main(dest_name):
    dest_addr = socket.gethostbyname(dest_name)
    port = 33434
    max_hops = 30
    icmp = socket.getprotobyname('icmp')
    udp = socket.getprotobyname('udp')
    ttl = 1
    while True:
        recv_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
        send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
        send_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
        recv_socket.bind(("", port))
        send_socket.sendto("", (dest_name, port))
        curr_addr = None
        curr_name = None
        recv_socket.settimeout(1)
        try:
            _, curr_addr = recv_socket.recvfrom(512)
            curr_addr = curr_addr[0]
            try:
                curr_name = socket.gethostbyaddr(curr_addr)[0]
            except socket.error:
                curr_name = curr_addr
        except socket.timeout:
            pass
        finally:
            send_socket.close()
            recv_socket.close()

        if curr_addr is not None:
            curr_host = "%s (%s)" % (curr_name, curr_addr)
        else:
            curr_host = "*"
        print "%d\t%s" % (ttl, curr_host)

        ttl += 1
        if curr_addr == dest_addr or ttl > max_hops:
            break

if __name__ == "__main__":
    main('google.com')
  • Could this be an issue with the firewall or some rule of your antivirus? – ederollora Mar 26 '14 at 23:47
  • Disabled windows firewall and works on linux on same network, so its not the network firewall. also works on windows xp – PhilStevenson Mar 27 '14 at 12:55
  • Happened to me too, I just get '*'. Hard to explain whats happening – ederollora Mar 27 '14 at 16:10
  • if you look at a wireshark capture when its running, it sends udp packet and you see the replies from hosts but python does not register them – PhilStevenson Mar 27 '14 at 16:23
  • 1
    I'm not 100%, but I think MS nurfed raw sockets since Vista. Might be that the only way (without custom network driver) to send ICMP packets is through a specific Win API library + Python ctypes. I can't find a decent reference to this anyware though. I do remember looking into it when doing windows C++ code and having to use a different library from winsocks. /vague-speculative-answer – Zv_oDD Jan 27 '16 at 18:21

0 Answers0