Skip to main content

pyshark

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

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.

Usage

Reading from a capture file:

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: 684s
        Identification: 0x254f (9551)
        Flags: 0x00
        Fragment offset: 0
        Time to live: 1
        Protocol: UDP (17)
        Header checksum: 0xe148 [correct]
        Source: BLANKED
        Destination: BLANKED
  ...

Reading from a live interface:

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

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:

packet['ip'].dst
>>> 192.168.0.1
packet.ip.src
>>> 192.168.0.100
packet[2].src
>>> 192.168.0.100

Release files for pyshark 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyshark 0.3.3
File Size Uploaded
pyshark-0.3.3.zip 21.0 kB Details

Release files / pyshark-0.3.3.zip

Download URL pyshark-0.3.3.zip
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
940020312979f77354236ac19f0bdadb80fa25c276b413b5a1e41d9d75e83e6d
BLAKE2b-256 checksum
How to use checksums
12ef8827cf8b36c462ec4a613c65422449d226f6435eb925b320837a462a1f26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2.2

1 release file

0.4.2.1

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.3.8

1 release file

0.3.7.8

1 release file

0.3.7.6

1 release file

0.3.7.5

1 release file

0.3.7.4

1 release file

0.3.7.3

1 release file

0.3.7.2

1 release file

0.3.7.1

1 release file

0.3.6.3

1 release file

0.3.6.2

1 release file

0.3.6.1

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

This release

0.3.3 This release

1 release file

0.3.2

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.2

0.2.1

1 release file

0.2

1 release file

0.1.5

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page