Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

List TCP Connections Sorted By Host and Most Connections

July 19, 2023 — Gregg Szumowski

Assuming your system still has netstat installed (Slackware 15.0 does :^), you can summarize the TCP connections on you host using the following command:

$ netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r

3 52.50.230.xxx
3 104.18.27.xxx
3 104.18.26.xxx
2 205.166.94.xx
2 192.168.1.xx
2 142.251.40.xxx
2 104.18.13.xx
1 74.120.9.xxx
1 66.255.245.xxx
1 54.154.65.xxx
1 52.96.182.xxx
1 45.56.116.xxx
1 45.33.73.xxx
1 34.117.65.xx
1 20.190.135.xx
1 192.168.122.xxx
1 192.168.1.xx
1 172.253.63.xxx
1 162.159.61.x
1 162.125.21.x
1 142.251.40.xxx
1 142.251.32.xxx
1 142.251.16.xxx
1 127.0.0.x

Tags: cli, networking, netstat, motd