Pure Python package for reading and parsing libpcap savefiles.
Project description
pypcapfile is a pure Python library for handling libpcap savefiles.
Installing
sudo pip install pypcapfile
git clone git://github.com/kisom/pypcapfile.git
cd pypcapfile
./setup.py install
Introduction
The core functionality is implemented in pcapfile.savefile:
>>> from pcapfile import savefile
>>> testcap = open('test.pcap', 'rb')
>>> capfile = savefile.load_savefile(testcap, verbose=True)
[+] attempting to load test.pcap
[+] found valid header
[+] loaded 11 packets
[+] finished loading savefile.
>>> print capfile
little-endian capture file version 2.4
microsecond time resolution
snapshot length: 65535
linklayer type: LINKTYPE_ETHERNET
number of packets: 11
You can take a look at the packets in capfile.packets:
>>> pkt = capfile.packets[0]
>>> pkt.raw()
<binary data snipped>
>>> pkt.timestamp
1343676707L
Automatically decoding layers
>>> from pcapfile import savefile
>>> from pcapfile.protocols.linklayer import ethernet
>>> from pcapfile.protocols.network import ip
>>> import binascii
>>> testcap = open('samples/test.pcap', 'rb')
>>> capfile = savefile.load_savefile(testcap, verbose=True)
[+] attempting to load samples/test.pcap
[+] found valid header
[+] loaded 3 packets
[+] finished loading savefile.
>>> eth_frame = ethernet.Ethernet(capfile.packets[0].raw())
>>> print eth_frame
ethernet from 00:11:22:33:44:55 to ff:ee:dd:cc:bb:aa type IPv4
>>> ip_packet = ip.IP(binascii.unhexlify(eth_frame.payload))
>>> print ip_packet
ipv4 packet from 192.168.2.47 to 173.194.37.82 carrying 44 bytes
and this example:
>>> from pcapfile import savefile
>>> testcap = open('samples/test.pcap', 'rb')
>>> capfile = savefile.load_savefile(testcap, layers=1, verbose=True)
[+] attempting to load samples/test.pcap
[+] found valid header
[+] loaded 3 packets
[+] finished loading savefile.
>>> print capfile.packets[0].packet.src
00:11:22:33:44:55
>>> print capfile.packets[0].packet.payload
<hex string snipped>
and lastly:
>>> from pcapfile import savefile
>>> testcap = open('samples/test.pcap', 'rb')
>>> capfile = savefile.load_savefile(testcap, layers=2, verbose=True)
>>> print capfile.packets[0].packet.payload
ipv4 packet from 192.168.2.47 to 173.194.37.82 carrying 44 bytes
The interface is still a bit messy.
Future planned improvements
IP options parsing (END and NOP is supported)
IPv6 support
TCP options parsing
ARP support
TODO
write unit tests
add __repr__ method that shows all of the values of the fields in IP packets and Ethernet frames.
See also
The project’s PyPi page.
The project’s Sphinx documentation on PyPI
The libpcap homepage
Contributors
A list of the project’s contributors may be found in the AUTHORS file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pypcapfile-0.12.0.tar.gz
.
File metadata
- Download URL: pypcapfile-0.12.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3328e2136980468b0906bbe05a5a6e4e506a6f1a8451cf80393814c31e6f3b7f |
|
MD5 | ec0b56358357921d9de705c3d52de576 |
|
BLAKE2b-256 | 5ca870677db49ecd688c7207e525664864d709f4aa2f76c29964cc93825f34b8 |
File details
Details for the file pypcapfile-0.12.0.linux-x86_64.tar.gz
.
File metadata
- Download URL: pypcapfile-0.12.0.linux-x86_64.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b1aa22b1682e327728750490334d5cc5a44a5a312349742bfe5a579dc15242f |
|
MD5 | 0bc114b1de2556d6ddf6602d2929a8ce |
|
BLAKE2b-256 | ff16cc0757bb3de3ef304e5ce080bba079df1da31703dddbb4b0d1d547e854fc |
File details
Details for the file pypcapfile-0.12.0-1.src.rpm
.
File metadata
- Download URL: pypcapfile-0.12.0-1.src.rpm
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e0914ba0147ab8c1c2e28dbfe043d48fb7431de8ae3dedc4719e6c96b30d987 |
|
MD5 | 151041cc3ea3a51a5ee6c06c346fa452 |
|
BLAKE2b-256 | 73523ea7f41fcd6b8b91885851f0dbf4e1e2e0a88a7f7b1a58047966e93a99be |
File details
Details for the file pypcapfile-0.12.0-1.noarch.rpm
.
File metadata
- Download URL: pypcapfile-0.12.0-1.noarch.rpm
- Upload date:
- Size: 47.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a51d809d971c720e3d94ddb7a5b19e79f93016a0af2430cb6ba4ef1fab21bb9 |
|
MD5 | cbc926aa0978082c38164b57fa1fa305 |
|
BLAKE2b-256 | 960417c540a47b837dd8f4a8959da698f7bf51e0237d7bb4a8499eaf1c21dee6 |