# pyshark
Python wrapper for tshark, allowing python packet parsing using wireshark dissectors.
Extended documentation: http://kiminewt.github.io/pyshark
**Looking for contributors** - for various reasons I have a hard time finding time to maintain and enhance the package at the moment. Any pull-requests will be reviewed and if any one is interested and is suitable, I will be happy to include them in the project. Feel free to mail me at dorgreen1 at gmail.
There are quite a few python packet parsing modules, this one is different because it doesn't actually parse any packets, it simply uses tshark's (wireshark command-line utility) ability to export XMLs to use its parsing.
This package allows parsing from a capture file or a live capture, using all wireshark dissectors you have installed.
Tested on windows/linux.
## Installation
### Version support
Python 3.7+ is supported. An unsupported Python 2 version exists as [pyshark-legacy](https://github.com/KimiNewt/pyshark-legacy).
Supports all modern versions of tshark / wireshark but certain features may be unavailable on older versions.
### All Platforms
Simply run the following to install the latest from pypi
```bash
pip install pyshark
```
Or install from the git repository:
```bash
git clone https://github.com/KimiNewt/pyshark.git
cd pyshark/src
python setup.py install
```
### Mac OS X
You may have to install libxml which can be unexpected. If you receive an error from clang or an error message about libxml, run the following:
```bash
xcode-select --install
pip install libxml
```
You will probably have to accept a EULA for XCode so be ready to click an "Accept" dialog in the GUI.
## Usage
### Reading from a capture file:
```python
>>> import pyshark
>>> cap = pyshark.FileCapture('/tmp/mycapture.cap')
>>> cap
<FileCapture /tmp/mycapture.cap (589 packets)>
>>> print cap[0]
Packet (Length: 698)
Layer ETH:
Destination: BLANKED
Source: BLANKED
Type: IP (0x0800)
Layer IP:
Version: 4
Header Length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
Total Length: 684
Identification: 0x254f (9551)
Flags: 0x00
Fragment offset: 0
Time to live: 1
Protocol: UDP (17)
Header checksum: 0xe148 [correct]
Source: BLANKED
Destination: BLANKED
...
```
#### Other options
* **param keep_packets**: Whether to keep packets after reading them via next().
Used to conserve memory when reading large caps.
* **param input_file**: Either a path or a file-like object containing either a
packet capture file (PCAP, PCAP-NG..) or a TShark xml.
* **param display_filter**: A display (wireshark) filter to apply on the cap
before reading it.
* **param only_summaries**: Only produce packet summaries, much faster but includes
very little information
* **param disable_protocol**: Disable detection of a protocol (tshark > version 2)
* **param decryption_key**: Key used to encrypt and decrypt captured traffic.
* **param encryption_type**: Standard of encryption used in captured traffic (must
be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK.
* **param tshark_path**: Path of the tshark binary
### Reading from a live interface:
```python
>>> capture = pyshark.LiveCapture(interface='eth0')
>>> capture.sniff(timeout=50)
>>> capture
<LiveCapture (5 packets)>
>>> capture[3]
<UDP/HTTP Packet>
for packet in capture.sniff_continuously(packet_count=5):
print('Just arrived:', packet)
```
#### Other options
* **param interface**: Name of the interface to sniff on. If not given, takes
the first available.
* **param bpf_filter**: BPF filter to use on packets.
* **param display_filter**: Display (wireshark) filter to use.
* **param only_summaries**: Only produce packet summaries, much faster but
includes very little information
* **param disable_protocol**: Disable detection of a protocol (tshark > version 2)
* **param decryption_key**: Key used to encrypt and decrypt captured traffic.
* **param encryption_type**: Standard of encryption used in captured traffic
(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK).
* **param tshark_path**: Path of the tshark binary
* **param output_file**: Additionally save captured packets to this file.
### Reading from a live interface using a ring buffer
```python
>>> capture = pyshark.LiveRingCapture(interface='eth0')
>>> capture.sniff(timeout=50)
>>> capture
<LiveCapture (5 packets)>
>>> capture[3]
<UDP/HTTP Packet>
for packet in capture.sniff_continuously(packet_count=5):
print('Just arrived:', packet)
```
#### Other options
* **param ring_file_size**: Size of the ring file in kB, default is 1024
* **param num_ring_files**: Number of ring files to keep, default is 1
* **param ring_file_name**: Name of the ring file, default is /tmp/pyshark.pcap
* **param interface**: Name of the interface to sniff on. If not given, takes
the first available.
* **param bpf_filter**: BPF filter to use on packets.
* **param display_filter**: Display (wireshark) filter to use.
* **param only_summaries**: Only produce packet summaries, much faster but
includes very little information
* **param disable_protocol**: Disable detection of a protocol (tshark > version 2)
* **param decryption_key**: Key used to encrypt and decrypt captured traffic.
* **param encryption_type**: Standard of encryption used in captured traffic
(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK).
* **param tshark_path**: Path of the tshark binary
* **param output_file**: Additionally save captured packets to this file.
### Reading from a live remote interface:
```python
>>> capture = pyshark.RemoteCapture('192.168.1.101', 'eth0')
>>> capture.sniff(timeout=50)
>>> capture
```
#### Other options
* **param remote_host**: The remote host to capture on (IP or hostname).
Should be running rpcapd.
* **param remote_interface**: The remote interface on the remote machine to
capture on. Note that on windows it is not the device display name but the
true interface name (i.e. \\Device\\NPF_..).
* **param remote_port**: The remote port the rpcapd service is listening on
* **param bpf_filter**: A BPF (tcpdump) filter to apply on the cap before
reading.
* **param only_summaries**: Only produce packet summaries, much faster but
includes very little information
* **param disable_protocol**: Disable detection of a protocol (tshark > version 2)
* **param decryption_key**: Key used to encrypt and decrypt captured traffic.
* **param encryption_type**: Standard of encryption used in captured traffic
(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK).
* **param tshark_path**: Path of the tshark binary
### Accessing packet data:
Data can be accessed in multiple ways.
Packets are divided into layers, first you have to reach the appropriate layer and then you can select your field.
All of the following work:
```python
>>> packet['ip'].dst
192.168.0.1
>>> packet.ip.src
192.168.0.100
>>> packet[2].src
192.168.0.100
```
To test whether a layer is in a packet, you can use its name:
```python
>>> 'IP' in packet
True
```
To see all possible field names, use the `packet.layer.field_names` attribute (i.e. `packet.ip.field_names`) or the autocomplete function on your interpreter.
You can also get the original binary data of a field, or a pretty description of it:
```python
>>> p.ip.addr.showname
Source or Destination Address: 10.0.0.10 (10.0.0.10)
# And some new attributes as well:
>>> p.ip.addr.int_value
167772170
>>> p.ip.addr.binary_value
b'\n\x00\x00\n'
```
### Decrypting packet captures
Pyshark supports automatic decryption of traces using the WEP, WPA-PWD, and WPA-PSK standards (WPA-PWD is
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
pysharktshark 的 Python 包装器,允许使用 wireshark 解析器解析 Python 数据包。扩展文档http://kiminewt.github.io/pyshark寻找贡献者- 由于各种原因,我目前很难找到时间来维护和改进该软件包。任何拉取请求都会被审查,如果有人感兴趣并且合适,我很乐意将他们纳入项目。请随时给我发邮件,地址是 dorgreen1@gmail。有相当多的 python 数据包解析模块,这个模块不同,因为它实际上并不解析任何数据包,它只是使用 tshark(wireshark 命令行实用程序)导出 XML 的能力来使用其解析。此软件包允许使用您已安装的所有 wireshark 解析器从捕获文件或实时捕获中进行解析。已在 windows/linux 上测试。安装版本支持支持 Python 3.7+。pyshark-legacy是不受支持的 Python 2 版本。支持所有现代版本的 tshark / wireshark,但某些功能在旧版本上可能不可用。所有平台只需运行以下命令即可从 pypi 安装最新版本
资源推荐
资源详情
资源评论




























收起资源包目录












































































共 61 条
- 1
资源评论


徐浪老师
- 粉丝: 9523
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 用MATLAB编写程序对机械振动信号进行分析2.doc
- 图像中对火灾与烟雾的目标检测识别
- 湖北曙光软件园项目前期策划.pptx
- 通信管道工程施工组织方案.doc
- 单片机热水器水温控制系统的方案设计书.doc
- 智慧城市解决方案.ppt
- 网络及其系统设计实施方案.docx
- 大连海事局大连海岸电台通信设备配套设施维护项目-辽宁海事局.doc
- 生物技术基因工程.ppt
- 大数据审计下统计分析方法研究.docx
- 基于项目管理理论工程项目风险管理研究开题报告.doc
- 基于STM32单片机6轴差分控制器应用设计.docx
- 区块链技术与供应链金融结合研究.docx
- 基于单片机单片机期末课程方案设计书.doc
- 测绘工程项目管理方案.doc
- 档案信息化建设与工程档案管理的重要性分析.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
