netstat
netstat -an|awk '/^tcp/{++S[$NF]}END{for (a in S)print a,S[a]}'
ss -ant|awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}'
It may have the strength, but the effort, struggle, worthy of the heart.
netstat -an|awk '/^tcp/{++S[$NF]}END{for (a in S)print a,S[a]}'
ss -ant|awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}'