通过Pipeline向Wireshark发送实时数据

下面的代码读取pcapng文件,并将数据通过Pipeline发送给Wireshark。nrf Sniffer即是通过这种方式进行BLE实时数据抓包显示的。 

# Win32 Wireshark named pipes example
# Requires Python for Windows and the Python for Windows Extensions:
# http://www.python.org
# http://sourceforge.net/projects/pywin32/

# https://wiki.wireshark.org/CaptureSetup/Pipes

import win32pipe, win32file
import time
import subprocess

#open Wireshark, configure pipe interface and start capture (not mandatory, you can also do this manually)
wireshark_cmd=['D:\SoftwareInstallFolder\Wireshark\Wireshark.exe', r'-i\\.\pipe\wireshark','-k']
proc=subprocess.Popen(wireshark_cmd)

#create the named pipe \\.\pipe\wireshark
pipe = win32pipe.CreateNamedPipe(
    r'\\.\pipe\wireshark',
    win32pipe.PIPE_ACCESS_OUTBOUND,
    win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT,
    1, 65536, 65536,
    300,
    None)

#connect to pipe
win32pipe.ConnectNamedPipe(pipe, None)

#open and read an arbitrary pcap file (file must in same folder than script)
cf = open(r'le_secure_connections.pcapng', 'rb')
data = cf.read()

#wait 2 second (not mandatory, but this let watching data coming trough the pipe)
time.sleep(2)

#send pcap data trough the pipe
win32file.WriteFile(pipe, data)

#then pcap data appears into wireshark

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值