0

我尝试通过ppp链接发送icmp包,但是sr收不到回复,tcpdump ppp0就ok了!

sh-4.2# tcpdump -i ppp0 -n icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode  
listening on ppp0, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
23:52:58.595117 IP 219.240.73.152 > 106.120.159.142: ICMP echo request, id 10915, seq 1, length 8
23:52:58.618401 IP 106.120.159.142 > 219.240.73.152: ICMP echo reply, id 10915, seq 1, length 8

我的代码如下,结果超时!Scapy版本是2.4.3


import os  
from scapy.all import *

conf.route.resync()  
packet = IP(dst="www.baidu.com")/ICMP(id=10915, seq=1)  
ans,unans = sr(packet, filter='icmp', verbose=0, timeout=3)  
if ans is None or len(ans) <= 0:  
    result = {"ans": len(ans), "unans": len(unans), "error": "timeout"}    
    print(result)  
    return

tx = ans[0][0]  
rx = ans[0][1]  
time = '%.2f' % ((rx.time-tx.sent_time) * 1000)   
ip = rx.sprintf("%IP.src%")   
result = {"ip": ip, "time": time}  
print(result)
4

0 回答 0