Skip to content

Instantly share code, notes, and snippets.

@peterc
Created April 4, 2009 01:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save peterc/90077 to your computer and use it in GitHub Desktop.
Save peterc/90077 to your computer and use it in GitHub Desktop.
urlmonitor - print out the URLs requested system wide on the main network interface
# urlmonitor - print out the URLs requested system wide on the main network interface
# Accept a network interface name as an optional argument
iface = ARGV.first
# No interface specified? Try to guess which one is king..
unless iface
`ifconfig -l`.split.each do |iface|
next if iface =~ /^lo/
break if `ifconfig #{iface}` =~ /inet (0|1|2)/
end
end
# Get tcpdump running, grep out relevant HTTP headers and build them
# in to URLs
STDOUT.sync = true
IO.popen(%{sudo tcpdump -i en1 -n -s 0 -w - | grep -a --line-buffered -E "Host\: .*|GET \/.*"}, 'r') do |pipe|
pipe.sync = true
while line = pipe.gets
path = $1.chomp and host = nil if line =~ /GET (.*?)\s/
host = $1.chomp if line =~ /Host: (.*)/
if path && host
puts "http://#{host}#{path}"
path = host = nil
end
end
end
@mbonaci
Copy link

mbonaci commented Aug 17, 2015

You hardcoded en1.
It doesn't output a thing for me, what could be the problem (I'd really like to have this one in my toolbox)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment