Skip to content

Instantly share code, notes, and snippets.

@picatz
Created November 5, 2016 23:35
Show Gist options
  • Save picatz/076cbd285972e9de4c6bdb8e31e27b26 to your computer and use it in GitHub Desktop.
Save picatz/076cbd285972e9de4c6bdb8e31e27b26 to your computer and use it in GitHub Desktop.
PacketFu example setting a Berkeley Packet Filter syntax for a capture.
require 'packetfu'
# get the default routable interface
iface = PacketFu::Utils.default_int
# Get my local ip
my_ip = PacketFu::Utils.ifconfig(iface)[:ip_saddr]
# Create a new capture on the en0 interface, just because I can
cap = PacketFu::Capture.new(:iface => 'en0')
# Set the bpf to filter ipv4 tcp connections with my host on port 22
cap.bpf(:filter => "ip host #{my_ip} and tcp port 22")
# Start capturing packs
cap.start
# Should need to process the packets with .stream() as I've shown earlier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment