使用 pyshark 过滤并选择第一个 GET 数据包

using pyshark to filter and to choose the first GET packet

我正在使用 pyshark 来过滤保存的 pcap 文件。 我使用的过滤器是:

http.request.method == GET && !ip.ttl==180 && ip.src==100.100.19.42

(最后有一个 link 到使用此过滤器后的 pcap 文件的屏幕截图。) 我的问题是,如何获取并打印 GET 数据包的 HTTP 层内容(如屏幕截图所示,位于第二行) 使用 python 代码。enter image description here 有没有办法搜索第一个GET包并找到它?

您可以改用 scapy。

from scapy.all import *
packets = rdpcap('your_capture.pcap')
for packet in packets:
    if packet['IP'].ttl != 180 and packet['IP'].src == '100.100.19.42':
        try:
            if 'GET' in packet['Raw'].load:
                print 'GET:',packet['Raw'].load
                return packet
        except:
            pass