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
| #!/usr/bin/env ruby | |
| # Collect netstat info | |
| out = %x[sudo netstat -4nlp|egrep -v "(unix|-)" 2>/dev/null |awk '{print $4,$NF}' | sort -k2 |sed '$ d' ] | |
| dot = {} | |
| out.split("\n").each do |line| | |
| host_port,pid_name = line.split() | |
| host,port = host_port.split(':') | |
| pid,name = pid_name.split('/') | |
| name = pid and pid = nil if name.nil? |