Created
May 13, 2016 12:54
-
-
Save osamu/aea60aac1dac0b99f56d674f48f2f29b 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 'rubygems' | |
require 'pcap' | |
require 'time' | |
if 2 != ARGV.size | |
STDERR.puts "Usage: #{$0} in.pcap out.pcap delta" | |
exit(2) | |
end | |
in_filename, out_filename = ARGV | |
inp = outc = outp = nil | |
begin | |
inp = Pcap::Capture.open_offline(in_filename) | |
outc = Pcap::Capture.open_dead(inp.datalink, inp.snaplen) | |
outp = Pcap::Dumper.open(outc, out_filename) | |
start_time = Time.parse("2016-5-12 14:44:00") | |
inp.each do |pkt| | |
next if pkt.time < start_time | |
outp.dump(pkt) | |
end | |
rescue Exception => e | |
STDERR.puts e.message,e.backtrace | |
ensure | |
inp.close if inp | |
outp.close if outp | |
outc.close if outc | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment