Skip to main content

Python wrapper for tshark, a fork for pyshark support Python3.5+

Project description

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

Infinite reading from a live interface with capture filter:
------------------------------

::

def packet_captured(packet):
print 'Just arrived:', packet

capture = pyshark.LiveCapture(interface='eth0', capture_filter='tcp')
capture.apply_on_packets(packet_captured)

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



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py3shark-0.4.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

py3shark-0.4.0-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file py3shark-0.4.0.tar.gz.

File metadata

  • Download URL: py3shark-0.4.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py3shark-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6cdfc547fce76bfeffede7e0807dd8bda487e5393a4ec28743d1836f9d35bfdc
MD5 3be10ba7f16c7e9c42c62b02f52303ef
BLAKE2b-256 3e6a2e6da925b931ab7d5cf6469a1bbc35ea5b389a47ac999748c8384e07f5fd

See more details on using hashes here.

File details

Details for the file py3shark-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py3shark-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a543d10e162a32e82ed071ef89fb14904fbf6ab51a51c9a7164de8d8130de015
MD5 4821d7ca2a4b05c23b49ee746bb3f7d7
BLAKE2b-256 04bafb9d2b5d21f6e00b7583fe44b88659755c5faf31ef7fd7ab7e80bd6bccd4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page