#windows #capture #networking #sniffer #api-bindings #ip-address

pktmon

A library for capturing network packets on Windows using the PktMon service

4 releases

0.1.3 Jan 23, 2025
0.1.2 Jan 23, 2025
0.1.1 Jan 21, 2025
0.1.0 Jan 21, 2025

#601 in Network programming

Download history 138/week @ 2025-01-15 287/week @ 2025-01-22

425 downloads per month

MIT license

61KB
1.5K SLoC

PktMon

Crates.io Version

PktMon is a library for capturing network packets on Windows using the PktMon service, which is included by default with Windows 10 and later.

See here for more information about the PktMon service.

See the Documentation for more information about the library.

Features

  • Easy-to-use high-level interface for packet capture
  • Filter support for protocol, ports, IP addresses, and more

Requirements

  • Windows 10 or later
  • Administrator privileges are required to talk to the PktMon service

Installation

cargo add pktmon

Usage

use pktmon::{Capture, filter::{PktMonFilter, TransportProtocol}};

fn main() {
    // Create a new capture instance
    let mut capture = Capture::new().unwrap();

    // Add a filter to capture UDP traffic on port 1234
    capture.add_filter(PktMonFilter {
        name: "UDP Filter".to_string(),
        transport_protocol: Some(TransportProtocol::UDP),
        port: 1234.into(),

        ..PktMonFilter::default()
    }).unwrap();
    
    // Start capturing
    capture.start().unwrap();
    
    // Get and print the next packet
    let packet = capture.next_packet().unwrap();
    println!("{:?}", packet.payload);
    
    // Stop capturing
    capture.stop().unwrap();
    
    // Unload the driver when done
    capture.unload().unwrap();
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Dependencies

~123MB
~2M SLoC