当前位置:网站首页>Copy pcap file with producer consumer model
Copy pcap file with producer consumer model
2022-07-26 07:50:00 【lepton126】
Using the producer consumer model, we can put the need for multiple cycles 、 Change the tightly coupled program architecture into a loosely coupled program architecture , In this way, you can easily add processing code for each line in the middle , For example, the following situation , In view of a pcap, Each package needs to be analyzed , The following code is just a preliminary framework , There is only one copy function .
#!/bin/env python3
import sys,os
import threading
import time
import queue
import dpkt
tspkt=[]
def consume(thread_name, q):
with open('./project3bak.pcap','wb') as pcapwr:
writer=dpkt.pcap.Writer(pcapwr)
while True:
#time.sleep(2)
product = q.get()
print("%s consume %s" % (thread_name, product))
writer.writepkt(pkt=product[1],ts=product[0])
def produce(thread_name, q):
with open('./project3.pcap','rb') as pcaprd:
reader=dpkt.pcap.Reader(pcaprd)
for ts,pkt in reader.readpkts():
tspkt=[ts,pkt]
q.put(tspkt)
q = queue.Queue()
p = threading.Thread(target=produce, args=("producer",q))
c = threading.Thread(target=consume, args=("consumer",q))
p.start()
c.start()
p.join()
边栏推荐
- Idea shortcut key
- WCF deployed on IIS
- 2021全球机器学习大会演讲稿
- OVS underlying implementation principle
- Logical volume management (LVM)
- Jmeter性能测试之将每次接口请求的结果保存到文件中
- :app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when
- Common templates for web development
- 音视频学习(十)——ps流
- Hystrix配置简单说明
猜你喜欢

Regression analysis code implementation

DCN (deep cross network) Trilogy

【推荐系统经典论文(十)】阿里SDM模型

【每日一题】919. 完全二叉树插入器

程序环境和预处理

NLP natural language processing - Introduction to machine learning and natural language processing (3)

From boosting to lamdamart

:app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when

ARIMA model for time series analysis and prediction

JWT quick start
随机推荐
[daily question 1] 919. Complete binary tree inserter
A tutorial for mastering MySQL database audit characteristics, implementation scheme and audit plug-in deployment
MySQL implementation plan
1. MySQL Architecture [MySQL advanced]
【uniapp】多种支付方式封装
Matlab drawing black spots on two / three-dimensional drawings
动态性能视图概述
【推荐系统经典论文(十)】阿里SDM模型
Idea shortcut key
Table fix specific rows
Use of views
Common database commands (special for review)
Program environment and pretreatment
Fang Wenshan, Jay Chou's best partner, will officially announce "Hualiu yuancosmos" on July 25
keras学习之:获取神经网络中间层的输出结果
2019中兴捧月·模型压缩方案
Solution to the problem of token loss when microservice feign is called
No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500
WCF deployed on IIS
utils 连接池