Skip to content

Instantly share code, notes, and snippets.

@picatz
Last active November 5, 2016 21:43
Show Gist options
  • Save picatz/ce71b351d804c38969696332aa05e1df to your computer and use it in GitHub Desktop.
Save picatz/ce71b351d804c38969696332aa05e1df to your computer and use it in GitHub Desktop.
require 'packetfu'
iface = PacketFu::Utils.default_int
cap = PacketFu::Capture.new(:iface => iface, :start => true)
# create an empty hash that starts for our base stats
stats = Hash.new(0)
# a hash inside of stats for types, which also starts at 0
stats[:types] = Hash.new(0)
# will parse packets providing summary data of packet contents
cap.stream.each do | packet |
packet_info = PacketFu::Packet.parse(packet)
type = packet_info.proto.last.to_sym
stats[:count] += 1
stats[:types][type] += 1
# clear screen and puts stats
system('clear')
puts stats
end
# => example output ...
# {:types=>{:TCP=>1832, :UDP=>100, :ARP=>2}, :count=>1934}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment