python 3.5 ICMP套接字无法在Windows上运行

时间:2016-06-12 16:31:07

标签: python sockets python-3.x network-programming network-protocols

我试图在python 3.5中进行traceroute实现。在linux上,这段代码运行正常。在Windows 10上,我有无限等待ICMP数据包。 Wireshark在Windows中看到ICMP数据包。

import socket

# Create a UDP and ICMP sockets
receiver = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.getprotobyname('ICMP'))

sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_IP, socket.IP_TTL, 1)

server_address = (socket.gethostbyname('google.com'), 33434)

try:
    # Send data
    receiver.bind(("", 33434))
    sent = sender.sendto(b"", server_address)
    data, server = receiver.recvfrom(512)
    print('received "%s"\n"%s"' % (data, server[0]))
finally:
    print('closing socket')
    sender.close()
    receiver.close()

0 个答案:

没有答案