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:
xxxxxxxxxx
1
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:
xxxxxxxxxx
1
6 172.68.11.24
2
4 172.69.54.62
3
4 172.68.244.83
4
2 162.158.94.163
5
2 162.158.158.200
6
2 162.158.154.66
7
1 198.41.230.75
8
1 172.69.71.73
9
1 172.69.55.171
10
1 172.69.54.224
11
1 172.69.35.58
12
1 172.69.159.137
13
1 172.69.134.86
14
1 172.68.63.106
15
1 172.68.62.45
16
1 172.68.62.39
17
1 172.68.246.67
18
1 172.68.246.43
19
1 172.68.245.66
20
1 172.68.245.150