List all IPs connected to your server along with connection count

Here’s how you can find out which IPs are connected to your Linux server, and how many times each IP is connected:

Group by IP:

netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Group by IP (but Handle IPv6):

netstat -ntu | awk ' $5 ~ /^(::ffff:|[0-9|])/ { gsub("::ffff:","",$5); print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

Group by IP and Port:

netstat -nt | awk -F":" '{print $2}' | sort | uniq -c

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *