小编use*_*326的帖子

Scapy如何获得ping时间?

我正在尝试编写一个scapy脚本,它可以在ping时间上取平均值,因此我需要在发送的ICMP echo/reply数据包和收到的回复数据包之间得到时间.现在,我有这个:

#! /usr/bin/env python
from scapy.all import *
from time import *

def QoS_ping(host, count=3):
  packet = Ether()/IP(dst=host)/ICMP()
  t=0.0
  for x in range(count):
      t1=time()
      ans=srp(packet,iface="eth0", verbose=0)
      t2=time()
      t+=t2-t1
  return (t/count)*1000
Run Code Online (Sandbox Code Playgroud)

问题是使用time()函数不会产生好的结果.例如,我在一个域上发现134毫秒,并且在同一个域上使用ping系统功能,我发现30毫秒(当然是平均值).

我的问题是:有没有办法通过scapy获得发送的数据包和收到的数据包之间的确切时间?我不想使用popen()函数或其他系统调用,因为我需要scapy来进行未来数据包管理.

python time networking ping scapy

12
推荐指数
1
解决办法
6711
查看次数

标签 统计

networking ×1

ping ×1

python ×1

scapy ×1

time ×1