File: readpcap.rb

package info (click to toggle)
ruby-packetfu 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,520 kB
  • sloc: ruby: 8,344; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby
# Usage:
# rvmsudo ruby examples/readpcap.rb test.pcap test.pcap

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

require 'packetfu'
include PacketFu

pcap_filename = ARGV[0] || 'test/sample.pcap'

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

puts "Loaded: PacketFu v#{PacketFu.version}"

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