Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python、dpkt和时间戳_Python_Http_Timestamp_Libpcap - Fatal编程技术网

python、dpkt和时间戳

python、dpkt和时间戳,python,http,timestamp,libpcap,Python,Http,Timestamp,Libpcap,我有个问题 对于pcap文件中的每个主机名,如何使用dpkt库和ts获得get和HTTP/1.0 200 OK(我指的是web服务器的时间延迟)之间的响应时间差 我的初步代码: #!/usr/bin/env python import dpkt f = open('mycapture.cap') pcap = dpkt.pcap.Reader(f) for ts, buf in pcap: eth = dpkt.ethernet.Ethernet(buf) ip = eth

我有个问题

对于pcap文件中的每个主机名,如何使用dpkt库和ts获得get和HTTP/1.0 200 OK(我指的是web服务器的时间延迟)之间的响应时间差

我的初步代码:

#!/usr/bin/env python

import dpkt

f = open('mycapture.cap')
pcap = dpkt.pcap.Reader(f)

for ts, buf in pcap:
    eth = dpkt.ethernet.Ethernet(buf)
    ip = eth.data
    tcp = ip.data

    if tcp.dport == 80 and len(tcp.data) > 0:
        http = dpkt.http.Request(tcp.data)
        print ts, http.headers['host']

f.close()
但它仍然是只获取请求的输出时间戳

它看起来像:

tcpdump -i eth0 -w pcapfile; python (command).py pcapfile

google.com 0.488183
facebook.com 0.045466
quora.com 0.032777

似乎您成功地获取了请求的第一个数据包,现在您需要获取响应的第一个数据包。。。比如:

if tcp.sport == 80 and len(tcp.data) > 0:
     # Here you can save the timestamp of the response and calculate the difference
祝你好运