ayaniimi213
8/29/2013 - 10:34 AM

pcapファイルを読み込んで、分ごとのtcp/ipパケット数を出力する。

pcapファイルを読み込んで、分ごとのtcp/ipパケット数を出力する。

#!/bin/env ruby

require 'pcap'

count = Hash.new

cap = Pcap::Capture.open_offline(ARGV.shift || 'traffic.cap')
cap.setfilter("ip")
cap.dispatch{|pkt|
   if pkt.ip? and pkt.tcp?
     key = (pkt.time.to_i/60)*60
# p key
     count[key] = 0 if count[key] == nil
     count[key] = count[key] + 1
# p count[key]
   end
}

count.each{|key,value|
   print "#{Time.at(key).to_s}: #{value}\n"
}