Last active
April 3, 2019 22:56
-
-
Save azet/6372454 to your computer and use it in GitHub Desktop.
boilerplate code for ruby packet sniffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool