python:如何使用DPKT从pcap文件中删除重复数据

python:如何使用DPKT从pcap文件中删除重复数据,python,dpkt,Python,Dpkt,我想要从PCAP文件中缝合http持久连接正文,但它包含一些 复制主体数据,如何删除这些数据 以下是我的代码: from mydpkt import Request from mydpkt import Reader, Ethernet rh_log = open('e:\\rh.pcap','rb') rh_file = Reader(rh_log) # p.setfilter('tcp port 80') expect_request_switch = False expect_resp

我想要从PCAP文件中缝合http持久连接正文,但它包含一些
复制主体数据,如何删除这些数据

以下是我的代码:

from mydpkt import Request
from mydpkt import Reader, Ethernet

rh_log = open('e:\\rh.pcap','rb')
rh_file = Reader(rh_log)
# p.setfilter('tcp port 80')
expect_request_switch = False
expect_respone_switch = False
body_lenth = 0
keep_alive_index = 0
body_persistent = ''
body_all = []
index = 0
for index, (ptime, pdata) in enumerate(rh_file).__iter__():
    p = Ethernet(pdata)
    ip = p.data
    if ip.__class__.__name__ == 'IP':
        dst_ip = '%d.%d.%d.%d' % tuple(map(ord, list(ip.dst)))
        src_ip = '%d.%d.%d.%d' % tuple(map(ord, list(ip.src)))
        tcp = ip.data
        # dport = tcp.dport
        if tcp.__class__.__name__ == 'TCP' and len(tcp.data) > 1:
            dport = tcp.dport
            sport = tcp.sport
            received_string = str(tcp.data)
            if expect_request_switch and expect_respone_switch and 'HTTP/1.1 200 OK' in received_string:
       expect_request_switch = expect_respone_switch = False
            if expect_request_switch:
                if 'HTTP/1.1 100 Continue' in tcp.data:
                    keep_alive_index = index
                    expect_respone_switch = True
                if (index >= (keep_alive_index + 1)) and expect_respone_switch and dport == 80:
                    body_persistent += received_string
                    body_persistent_lenth = len(body_persistent)
                    body_all.append(body_persistent)
                    expect_request_switch = False
                    expect_respone_switch = False
正文_持久=“”


也许再加上一些例子?向我们展示您面临的问题?到目前为止你都做了些什么?谢谢添加了我的代码…使用dpkt库并修复了一些代码可以添加一些示例吗?向我们展示您面临的问题?到目前为止你都做了些什么?谢谢添加了我的代码…使用dpkt库并修复了一些代码
            if dport == 80 and expect_respone_switch is False: