Skip to main content

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

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

pyshark-0.4.2.3.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

pyshark-0.4.2.3-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file pyshark-0.4.2.3.tar.gz.

File metadata

  • Download URL: pyshark-0.4.2.3.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.5

File hashes

Hashes for pyshark-0.4.2.3.tar.gz
Algorithm Hash digest
SHA256 7c221bf1b9f4fccb8793d8c0c3ce70255c3100f3b02a21232de4c5cd77291c3c
MD5 5483fc6f364287c70b2df267e9448b06
BLAKE2b-256 bf9356ee4d6859527b4bc2fb4f3966e8572944c680eb3dda2dfdc3975d542459

See more details on using hashes here.

File details

Details for the file pyshark-0.4.2.3-py3-none-any.whl.

File metadata

  • Download URL: pyshark-0.4.2.3-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.3

File hashes

Hashes for pyshark-0.4.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71b26d67825be6ed8e6dd7fc7bb33a7565fd017f604db60efd284b43d43456c8
MD5 726439686bbb5811977d5148d90ec3dd
BLAKE2b-256 4c185a6e432f1178a30966e50e580b3d1ebd128c0a456278fabea08cccfa13fd

See more details on using hashes here.

Supported by

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