Skip to content

Instantly share code, notes, and snippets.

@kylef
Created July 19, 2010 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylef/481946 to your computer and use it in GitHub Desktop.
Save kylef/481946 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
begin
require 'pcaplet'
rescue LoadError
require 'rubygems'
require 'pcaplet'
end
p = Pcaplet.new(ARGV.join(' '))
HTTP_REQUEST = Pcap::Filter.new('tcp and dst port 80', p.capture)
HTTP_RESPONSE = Pcap::Filter.new('tcp and src port 80', p.capture)
p.each_packet do |pkt|
if pkt.tcp? then
data = pkt.tcp_data
case pkt
when HTTP_REQUEST
if data and data =~ /^GET\s+(\S+)/
path = $1
host = pkt.dst.to_s
if data =~ /^Host:\s+(\S+)/
host = $1
end
host << ":#{pkt.dst_port}" if pkt.dport != 80
puts "#{pkt.src}:#{pkt.sport} > GET http://#{host}#{path}"
end
when HTTP_RESPONSE
if data and data =~ /^(HTTP\/.*)$/
status = $1
puts "#{pkt.dst}:#{pkt.dport} < #{status}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment