Skip to content

Instantly share code, notes, and snippets.

@picatz
Last active November 4, 2017 17:47
Show Gist options
  • Save picatz/c2507b925eab7e5e97d956e71503a973 to your computer and use it in GitHub Desktop.
Save picatz/c2507b925eab7e5e97d956e71503a973 to your computer and use it in GitHub Desktop.
Capture & Analyze 10 ICMP packets
require 'packetgen'
# capture an array of 10 parsed packets, using a bpf filter
icmps = PacketGen.capture(iface: 'eth0', filter: 'icmp', max: 10)
# analyze each packet's payload
icmps.each do |packet|
puts packet.body
end
# analyze each packet icmp header type
icmps.each do |packet|
puts packet.icmp.type
end
# get an array of each packet's icmp checksum
checksums = icmps.map { |packet| packet.icmp.checksum }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment