pyshark

Python wrapper for tshark, allowing python packet parsing using wireshark dissectors

https://github.com/kiminewt/pyshark

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    5 of 84 committers (6.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.8%) to scientific vocabulary

Keywords

capture-packets packet-capture python tshark wireshark

Keywords from Contributors

gtk qt tk wx astronomy astrophysics distributed
Last synced: 6 months ago · JSON representation

Repository

Python wrapper for tshark, allowing python packet parsing using wireshark dissectors

Basic Info
  • Host: GitHub
  • Owner: KimiNewt
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 544 KB
Statistics
  • Stars: 2,419
  • Watchers: 75
  • Forks: 441
  • Open Issues: 136
  • Releases: 16
Topics
capture-packets packet-capture python tshark wireshark
Created about 12 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

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.

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 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 capture[3]

for packet in capture.sniffcontinuously(packetcount=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 capture[3]

for packet in capture.sniffcontinuously(packetcount=5): print('Just arrived:', packet) ```

Other options

  • param ringfilesize: Size of the ring file in kB, default is 1024
  • param numringfiles: Number of ring files to keep, default is 1
  • param ringfilename: 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.intvalue 167772170 p.ip.addr.binaryvalue 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 the default).

```python

cap1 = pyshark.FileCapture('/tmp/capture1.cap', decryptionkey='password') cap2 = pyshark.LiveCapture(interface='wi0', decryptionkey='password', encryption_type='wpa-psk') ```

A tuple of supported encryption standards, SUPPORTEDENCRYPTIONSTANDARDS, exists in each capture class.

```python

pyshark.FileCapture.SUPPORTEDENCRYPTIONSTANDARDS ('wep', 'wpa-pwd', 'wpa-psk') pyshark.LiveCapture.SUPPORTEDENCRYPTIONSTANDARDS ('wep', 'wpa-pwd', 'wpa-psk') ```

Reading from a file using a display filter

Pyshark display filters can be helpful in analyzing application focused traffic. BPF filters do not offer as much flexibility as Wireshark's display filters.

```python

cap1 = pyshark.FileCapture('/tmp/capture1.cap', displayfilter="dns") cap2 = pyshark.LiveCapture(interface='en0', displayfilter="tcp.analysis.retransmission") ```

License

This project is licensed under MIT. Contributions to this project are accepted under the same license.

Owner

  • Name: Dor Green
  • Login: KimiNewt
  • Kind: user

GitHub Events

Total
  • Issues event: 12
  • Watch event: 174
  • Issue comment event: 21
  • Push event: 3
  • Pull request event: 16
  • Pull request review comment event: 4
  • Pull request review event: 3
  • Fork event: 31
Last Year
  • Issues event: 12
  • Watch event: 174
  • Issue comment event: 21
  • Push event: 3
  • Pull request event: 16
  • Pull request review comment event: 4
  • Pull request review event: 3
  • Fork event: 31

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 425
  • Total Committers: 84
  • Avg Commits per committer: 5.06
  • Development Distribution Score (DDS): 0.459
Past Year
  • Commits: 6
  • Committers: 6
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.833
Top Committers
Name Email Commits
Dor Green d****r@a****m 230
Bo Bayles b****s@g****m 27
bnlrnz l****b@t****e 15
Dor Green d****n@l****m 10
MiaoTony 4****y 9
Matt Carlson m****n@a****m 9
monkut s****s@g****m 7
laixintao g****i@b****n 7
ericbass 3****5@g****m 6
John Lyu p****n@o****m 4
Isidro Arias i****s@w****s 4
ZackAlfakir z****r@y****m 3
Michael Rigoni m****i@o****m 3
Zoltan Kelemen z****n@k****e 3
monkut n****n@h****m 3
Fabian Affolter f****n@a****h 2
Kirill Nikitin k****n@e****h 2
Ed a****r@e****e 2
Brénainn Woodsend b****d@g****m 2
Martin Gallo m****o@c****m 2
Martin Levy m****n@c****m 2
Matt Carlson m****n@g****m 2
Jonathan GAYVALLET j****t@g****m 2
georgschweflinghaus g****g@s****e 2
chribro88 c****n@l****u 2
albertwigmore a****t@a****k 2
ShellCode33 s****3@p****h 2
Roshan Pius r****s@c****g 2
Matthew Bradbury M****y@w****k 2
cclauss c****s@b****h 2
and 54 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 132
  • Total pull requests: 61
  • Average time to close issues: over 1 year
  • Average time to close pull requests: 4 months
  • Total issue authors: 121
  • Total pull request authors: 46
  • Average comments per issue: 2.01
  • Average comments per pull request: 0.93
  • Merged pull requests: 32
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 13
  • Pull requests: 18
  • Average time to close issues: 28 days
  • Average time to close pull requests: 15 days
  • Issue authors: 13
  • Pull request authors: 13
  • Average comments per issue: 0.54
  • Average comments per pull request: 0.28
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • miaotony (8)
  • matan1008 (2)
  • ghasemi931 (2)
  • sampatti37 (2)
  • tranzmatt (2)
  • elieejs (1)
  • tonyle72 (1)
  • jeyabharathi12 (1)
  • alexandre0119 (1)
  • geyuchen (1)
  • markgras (1)
  • linkingli (1)
  • amo1101 (1)
  • mmm29 (1)
  • hemant239 (1)
Pull Request Authors
  • KimiNewt (6)
  • miaotony (4)
  • rshayer95 (3)
  • irl (2)
  • aparcar (2)
  • chribro88 (2)
  • amlamarra (2)
  • sbrun (2)
  • veedubb (2)
  • Diegomangasco (2)
  • Vladimir-Chan (2)
  • kmikov (2)
  • RabbitSudo (2)
  • mahtin (2)
  • jmiah717 (2)
Top Labels
Issue Labels
bug (66) old-auto-close (19) enhancement (18)
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 1,062,649 last-month
  • Total docker downloads: 4,574,344
  • Total dependent packages: 20
    (may contain duplicates)
  • Total dependent repositories: 265
    (may contain duplicates)
  • Total versions: 54
  • Total maintainers: 1
pypi.org: pyshark

Python wrapper for tshark, allowing python packet parsing using wireshark dissectors

  • Versions: 48
  • Dependent Packages: 20
  • Dependent Repositories: 263
  • Downloads: 1,062,601 Last month
  • Docker Downloads: 4,574,344
Rankings
Docker downloads count: 0.7%
Dependent packages count: 0.8%
Downloads: 0.8%
Dependent repos count: 0.9%
Average: 1.2%
Stargazers count: 1.6%
Forks count: 2.6%
Maintainers (1)
Last synced: 6 months ago
pypi.org: pyshark-legacy

Python wrapper for tshark, allowing python packet parsing using wireshark dissectors

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 48 Last month
Rankings
Stargazers count: 1.6%
Forks count: 2.6%
Dependent packages count: 7.4%
Average: 8.4%
Dependent repos count: 11.9%
Downloads: 18.6%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: pyshark
  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Forks count: 8.0%
Stargazers count: 8.7%
Average: 25.5%
Dependent repos count: 34.0%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • appdirs *
  • lxml *
  • packaging *
  • py *
  • pytest *
src/setup.py pypi
  • appdirs *
  • lxml *
  • packaging *
  • py *