Skip to content

Instantly share code, notes, and snippets.

@mitio
Created April 2, 2013 13:54
Show Gist options
  • Save mitio/5292372 to your computer and use it in GitHub Desktop.
Save mitio/5292372 to your computer and use it in GitHub Desktop.
Clumsy one-liners from hell
grep -E '^Listen ' /usr/local/etc/apache/httpd.conf | sed 's/:/./' | sed 's/Listen //' | ruby -e 'conns = []; while conn = gets; conns << conn.strip; end; system "netstat -an|grep tcp|grep -v LISTEN|grep -E \"\\b#{conns.join "\\b|\\b"}\\b\"";' | awk '{ print $5 }' | ruby -e 'conns = Hash.new(0); while conn = gets; parts = conn.strip.split("."); ip = parts[0..-2].join("."); port = parts[-1]; conns[ip] += 1; end; conns.sort_by { |ip, count| -count }.each { |ip, count| puts "IP: #{ip.ljust(25)} connections: #{count}" } ;nil'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment