Skip to content

Instantly share code, notes, and snippets.

@azet
Last active April 3, 2019 22:56
Show Gist options
  • Save azet/6372454 to your computer and use it in GitHub Desktop.
Save azet/6372454 to your computer and use it in GitHub Desktop.
boilerplate code for ruby packet sniffer
#!/usr/bin/env ruby
require 'packetfu'
# filter = argv[0] - tcpdump style.
# e.g. 'dst host bla.dom.tld and port http and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
# to cap. http traffic. or 'host W.X.Y.Z' to cap a speficic host/ip
cap = PacketFu::Capture.new(:start => true)
cap.save(:filter => ARGV[0])
cap.stream.each do |packet, index|
pkt = PacketFu::Packet.parse packet
puts "\n>> DISSECTION:\n"
puts pkt.dissect
puts "\n>> PAYLOAD:\n"
puts pkt.payload
puts "\n>> SIZE:\n"
puts pkt.size
end
@iamhabbeboy
Copy link

cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment