https://github.com/picatz/packetz
🦈 Packet capturing library built with LibPcap
https://github.com/picatz/packetz
crystal libpcap opensource packet-analyzer packet-capture packet-sniffer pcap
Last synced: 8 months ago
JSON representation
🦈 Packet capturing library built with LibPcap
- Host: GitHub
- URL: https://github.com/picatz/packetz
- Owner: picatz
- License: mit
- Created: 2017-11-06T03:25:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-22T22:32:00.000Z (about 8 years ago)
- Last Synced: 2025-04-22T19:45:07.430Z (11 months ago)
- Topics: crystal, libpcap, opensource, packet-analyzer, packet-capture, packet-sniffer, pcap
- Language: Crystal
- Homepage:
- Size: 24.4 KB
- Stars: 24
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🦈 Packetz
Packet capturing library built with [LibPcap](https://github.com/the-tcpdump-group/libpcap).
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
packetz:
github: picatz/packetz
```
## Basic Usage
```crystal
require "packetz"
# start packet capture on default interface
Packetz.capture do |packet|
puts packet.hexdump
end
```
#### Craft your Capture
```crystal
# create capture handler
cap = Packetz.capture
# stop the capture with ctl+C
Signal::INT.trap do
puts "Stopping!"
cap.stop!
exit
end
# setup the handler
cap.snapshot_length = 33333
cap.promiscuous_mode = true
cap.monitor_mode = true
# start capturing
cap.start!
# do something with each packet and its pcap header
cap.each do |packet, pcap_header|
# something
end
```
#### Network Interfaces
```crystal
# get default interface to capture on
Packetz.interfaces.default
```
```crystal
# get all possible interfaces
Packetz.interfaces.all do |interface|
puts interface
end
```
## Contributors
- [picat](https://github.com/picatz) Kent 'picat' Gruber - creator, maintainer
- [maiha](https://github.com/maiha) maiha - `pcap.cr`
- [puppetpies](https://github.com/puppetpies) Brian Hood - `libpcap.cr`