Read pcap and assemble HTTP requests
Project description
Pcaper provides class to read pcap file, assemble and iterate HTTP requests. The package based on dpkt.
Installation
pip install pcaper
Import
import pcaper
reader = pcaper.HTTPRequest()
or
from pcaper import HTTPRequest
reader = HTTPRequest()
Examples
Iterate HTTP requests
Read pcap file, assemble and iterate HTTP requests
reader = pcaper.HTTPRequest()
params = {
'input': 'file.pcap',
}
for request in reader.read_pcap(params):
print request['origin']
Extract http headers
You can extract header by name
reader = pcaper.HTTPRequest()
params = {
'input': 'file.pcap',
}
for request in reader.read_pcap(params):
print request['headers']['host']
print request['headers']['content-length']
Filter packets
It is possible to filter out excess packets
reader = pcaper.HTTPRequest()
params = {
'input': 'file.pcap',
'filter': 'tcp.dst == 1.1.1.1'
}
for request in reader.read_pcap(params):
print request['origin']
You can combine tcp and ip filters in dpkt style
reader = pcaper.HTTPRequest()
params = {
'input': 'file.pcap',
'filter': '(ip.src == 10.4.0.136 or ip.dst == 10.1.40.61) and tcp.dport == 8888'
}
for request in reader.read_pcap(params):
print request['origin']
It is possible to use excluding filter in dpkt style
reader = pcaper.HTTPRequest()
params = {
'input': 'file.pcap',
'exfilter': 'tcp.dport == 8888 and ip.dst == 10.1.40.61'
}
for request in reader.read_pcap(params):
print request['origin']
Notes
New pcapng format is not supported by dpkt package, but you can convert input file from pcapng to pcap format with standard utility, which is installed with wireshark package.
mergecap file.pcapng -w out.pcap -F pcap
Scripts
parse_http
The parse_http script is installed to Python directory and can be executed directly in command line
It simplify parsing of pcap files. Just extract HTTP requests including its headers and body and print out complete data to console or file.
Print HTTP requests from pcap file:
parse_http file.pcap
Filter HTTP requests and write to external file:
parse_http -f "tcp.dport == 8080" -e "ip.dst == 10.10.10.10" -o file.out file.pcap
Print statistics about counted requests:
parse_http -f "ip.src == 10.10.10.10" -S file.pcap
Stats:
total: 1
complete: 1
incorrect: 0
incomplete: 0
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 Distribution
Hashes for pcaper-1.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99106b9c2743958fb52c7d77c0f06c33d5f85b9bd4ba28df295d202768943042 |
|
MD5 | 5334521d8ba82aa392b69712b1a8159e |
|
BLAKE2b-256 | a93c264c8cd2783f795731d0364368cf4bde57b2fa6b0cff37e2b624e448d78d |