Skip to content

Instantly share code, notes, and snippets.

@alter
alter / dot.rb
Created April 28, 2015 11:56
dot with horizontal orientation
#!/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?