Python:原始ICMP套接字无法接收ICMP消息

时间:2016-11-22 21:32:36

标签: python sockets icmp

我之前从未使用过python,并且我被要求使用python的原始套接字构建一个简单的traceroute。我需要将UDP发送到不可达的端口并解释ICMP以获得RTT和跳数。为了测试l是否实际收到了ICMP,我将TTL更改为3,并且wireshark告诉我已收到ICMP,但我的代码无法接收该消息

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)       
output = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
ttl = 3
destination = socket.gethostbyname("www.youtube.com")
client.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
client.sendto('include some message',(destination,44343))
output.bind((socket.gethostname(),0))
print 'receiving'
data, addr = output.recvfrom(5012)
print data
client.close()
output.close()

将卡在行数据上,addr = output.recvfrom(5012)。我该怎么办?

0 个答案:

没有答案