Skip to content

Commit

Permalink
Add packet parsing example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Claudius committed May 2, 2017
1 parent 9655da1 commit bb51ad9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/readpcap.rb
@@ -0,0 +1,23 @@
# Usage:
# rvmsudo ruby examples/readpcap.rb test.pcap test.pcap

# Path setting slight of hand:
$: << File.expand_path("../../lib", __FILE__)

require 'packetfu'

pcap_filename = ARGV[0].chomp

unless File.exists?(pcap_filename)
puts "PCAP input file #{pcap_filename} could not be found"
end

puts "Reading PCAP to packet array from #{File.expand_path(pcap_filename)}"
packet_array = PacketFu::PcapFile.file_to_array(pcap_filename)

packet_array.each do |pkt|
packet = PacketFu::Packet.parse(pkt)

# Do some stuff here (really any thing you want)
puts packet.class
end

0 comments on commit bb51ad9

Please sign in to comment.