EN
Linux - list all clients connected to my http server over 80 port
1
points
In this article, we're going to have a look at how to print all people/users/client connected to my http server (over 80
port) by tcp
/tcp6
protocol and their IP adresses with netstat
command under Bash in Linux.
Type in terminal:
netstat -tn 2>/dev/null | grep -E '\s[0-9.]+:80\s' | awk '{print $5}' | cut -d : -f 1 | sort | uniq -c | sort -nr
Where:
netstat -tn 2>/dev/null | returns informations all tcp /tcp6 connections |
grep -E '\s[0-9.]+:80\s' | filters rows that contains ip addres with 80 port using regular expressions |
awk '{print $5}' | prints only column 5th that is described as "Foreign Address " that contains connected client ip address with his remote port |
cut -d : -f 1 | extracts only ip address for connected client |
sort | sorts rows to let them to be counted with next command (uniq command) |
uniq -c | counts (-c ) neighbouring rows and print them as: number_of_rows row_text |
sort -nr | makes numeric sort (-n ) and reverse result (-r ) |
Console print:
6 172.68.11.24
4 172.69.54.62
4 172.68.244.83
2 162.158.94.163
2 162.158.158.200
2 162.158.154.66
1 198.41.230.75
1 172.69.71.73
1 172.69.55.171
1 172.69.54.224
1 172.69.35.58
1 172.69.159.137
1 172.69.134.86
1 172.68.63.106
1 172.68.62.45
1 172.68.62.39
1 172.68.246.67
1 172.68.246.43
1 172.68.245.66
1 172.68.245.150