Created
April 2, 2013 13:54
-
-
Save mitio/5292372 to your computer and use it in GitHub Desktop.
Clumsy one-liners from hell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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