当前位置:网站首页>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
边栏推荐
猜你喜欢

Matlab-二/三维图上绘制黑点

Sort: merge sort and quick sort

table 固定特定行

Deep learning model deployment

Crawler - > tpimgspider

系统架构&微服务

Regular expression rules and common regular expressions

Fang Wenshan, Jay Chou's best partner, will officially announce "Hualiu yuancosmos" on July 25

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

The bigger the project is, the bigger it is. This is how I split it
随机推荐
PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts
Command line execution and test report generation of JMeter performance test
Summary of distributed related interview questions
NLP natural language processing - Introduction to machine learning and natural language processing (3)
Matlab-二/三维图上绘制黑点
Lnmp+wordpress to quickly build a personal website
音视频学习(十)——ps流
FTP service
Leetcode 206. reverse chain list (2022.07.25)
Keras learning part: obtaining the output results of neural network middle layer
HOT100 hash
Learning Efficient Convolutional Networks Through Network Slimming
Leetcode sword finger offer special (I) integer
Introduction to C language (8)
博途PLC一阶滞后系统传递函数阶跃响应输出仿真(SCL)
1. MySQL Architecture [MySQL advanced]
Hcip--- MPLS detailed explanation and BGP route filtering
QT listview add controls and pictures
MMOE多目标建模
TensorFlow学习日记之tflearn