Sha256: 0f8d3c7cde80fd1988404e21ab7437a9852264f3f4773a959a4cdece99b17453

Contents?: true

Size: 733 Bytes

Versions: 6

Compression:

Stored size: 733 Bytes

Contents

#!/usr/bin/env ruby
require 'rubygems'
require 'pcaplet'
httpdump = Pcaplet.new('-s 1500')

HTTP_REQUEST  = Pcap::Filter.new('tcp and dst port 80', httpdump.capture)
HTTP_RESPONSE = Pcap::Filter.new('tcp and src port 80', httpdump.capture)

httpdump.add_filter(HTTP_REQUEST | HTTP_RESPONSE)
httpdump.each_packet {|pkt|
  data = pkt.tcp_data
  case pkt
  when HTTP_REQUEST
    if data and data =~ /^GET\s+(\S+)/
      path = $1
      host = pkt.dst.to_s
      host << ":#{pkt.dst_port}" if pkt.dport != 80
      s = "#{pkt.src}:#{pkt.sport} > GET http://#{host}#{path}"
    end
  when HTTP_RESPONSE
    if data and data =~ /^(HTTP\/.*)$/
      status = $1
      s = "#{pkt.dst}:#{pkt.dport} < #{status}"
    end
  end
  puts s if s
}

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
ruby-pcap-0.8.1 examples/httpdump.rb
ruby-pcap-0.8.0 examples/httpdump.rb
ruby-pcap-0.7.9 examples/httpdump.rb
ahobson-pcap-0.7.0 examples/httpdump.rb
romanbsd-pcap-0.7.0 examples/httpdump.rb
ruby-pcap-0.7.8 examples/httpdump.rb