当前位置:网站首页>Using ordered dictionary to copy pcap files
Using ordered dictionary to copy pcap files
2022-07-26 07:50:00 【lepton126】
#!/bin/env python3
#_*_coding:UTF-8_*_
import dpkt
import collections
import time
def main(file_path,filewr_path):
f=open(file_path,mode='rb')
try:
pcap=dpkt.pcap.Reader(f)
except:
pcap=dpkt.pcapng.Reader(f)
all_pcap_data=collections.OrderedDict()
count=0
for(ts,buf) in pcap:
# Here, we can add a target for buf The processing code of , This is read in pcap File processing buf
all_pcap_data[count]=(ts,buf)
count=count+1
f.close()
f=open(filewr_path,mode='wb')
pcap=dpkt.pcap.Writer(f)
for i in all_pcap_data:
# You can also add here for buf The processing code of , This is written to pcap File processing buf
pcap.writepkt(all_pcap_data.get(i)[1],ts=all_pcap_data.get(i)[0])
f.close()
if __name__=='__main__':
file_path="./project3.pcap"
filewr_path="./project3bak.pcap"
main(file_path,filewr_path)
The source file is project3.pcap, The file name after copying is project3bak.pcap, Code can be added in the middle to extract each package 、 Filtering and other operations
边栏推荐
猜你喜欢

WCF deployed on IIS

A tutorial for mastering MySQL database audit characteristics, implementation scheme and audit plug-in deployment

深度学习模型部署

Jmeter性能测试之命令行执行和生成测试报告

数据库基础

MMOE多目标建模

C # use log4net to record logs (basic chapter)

Interview question set

什么是消息订阅和发布?

Parameterization of JMeter performance test using CSV file
随机推荐
Hcip--- BGP comprehensive experiment
Model pruning 3: learning structured sparsity in deep neural networks
Come across the sea to see you
Wrong Addition
Learning Efficient Convolutional Networks Through Network Slimming
Installation of Baidu flying paste deep learning framework tutorial in Anaconda
PHP environment deployment
Lambda and stream
Regression analysis code implementation
《门锁》引爆独居安全热议 全新海报画面令人窒息
Jmeter性能测试之命令行执行和生成测试报告
什么是消息订阅和发布?
A tutorial for mastering MySQL database audit characteristics, implementation scheme and audit plug-in deployment
PXE efficient batch network installation
2022.7.22DAY612
系统架构&微服务
[classic thesis of recommendation system (10)] Alibaba SDM model
Common templates for web development
Lnmp+wordpress to quickly build a personal website
tensorflow2.x中的量化感知训练以及tflite的x86端测评