File: uniqpcap.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 (25 lines) | stat: -rw-r--r-- 772 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
# Uniqpcap.rb takes a pcap file, strips out duplicate packets, and
# writes them to a file.
#
# The duplicate pcap problem is common when I'm capturing
# traffic to/from a VMWare image, for some reason.
#
# Currently, the timestamp information is lost due to PcapRub's
# file read. For me, this isn't a big deal. Future versions
# will deal with timestamps correctly.

# Usage:
# ruby examples/uniqcap.rb test/sample.pcap

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

pcap_file = ARGV[0].chomp

in_array = PacketFu::Read.f2a(:file => pcap_file)

puts "Original Packets: #{in_array.size}"
puts "Uniq'd Packets: #{in_array.uniq.size}"

puts PacketFu::Write.a2f(:file => pcap_file + ".uniq", :arr => in_array.uniq).inspect