Last active
November 5, 2016 21:43
-
-
Save picatz/ce71b351d804c38969696332aa05e1df to your computer and use it in GitHub Desktop.
This file contains 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
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