# ------------------------------------------------------------------ # tcpports.rb Print TCP Port Information # usage : tcpports <capture-file> # # # ------------------------------------------------------------------ require 'win32ole' USAGE = "tcpports <capture-filename> " if ARGV.length != 1 puts USAGE exit 1 end InputFile = ARGV[0] UnsniffDB = WIN32OLE.new("Unsniff.Database") UnsniffDB.Open(InputFile) PacketIndex = UnsniffDB.PacketIndex (0..PacketIndex.Count-1).each do |idx| pkt = PacketIndex.Item(idx) layers = pkt.Layers layers.each do |lyr| if lyr.Name == "TCP" sport = lyr.FindField("Src Port") dport = lyr.FindField("Dest Port") print "s: #{sport.Value}\t\td: #{dport.Value}\n" end end end UnsniffDB.Close()