当前位置:网站首页>Pyshark tutorial

Pyshark tutorial

2022-06-21 06:11:00 Charming pie star

install

pip install pyshark

Use

for example : Analyze existing pcap file :

import pyshark

pcap = pyshark.FileCapture("test1.pcap", tshark_path="/Applications/Wireshark.app/Contents/MacOS/tshark")

The two parameters specify the input file and tshark route

then , You can use loop traversal pcap file ( You can also use subscripts ):

for p in pcap:
    print(p)

Output structure and wireshark What you see is consistent , give the result as follows :
 Insert picture description here
If you want to see it alone IP Layer or TCP or UDP In the words of the first floor , It only needs :

print(pcap[0].ip)

Output :
 Insert picture description here
With IP Layer as an example , If you want to extract one of these parameters separately :

print(pcap[0].ip.src)
print(pcap[0].ip.ttl)
print(pcap[0].ip.version)
print(pcap[0].ip.proto)

Output is as follows :
 Insert picture description here
How to see pcap What fields are available for the object ? Yes pcap Object use dir() Function

print(dir(pcap[0]))

give the result as follows :
 Insert picture description here
Empathy , How to see what fields are available in a certain layer ? With IP Layer as an example :

print(dir(pcap[0].ip))

Output is as follows :
 Insert picture description here

summary

It is OK for daily use , But the speed is average

原网站

版权声明
本文为[Charming pie star]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210556021449.html