List all IP addresses connected to your Server

We have multiple methods to list all the IP addressed, but below is a Unix command to list all the IP addresses connected to your server on port 80.

List all the IP Address

List all the IP Address

# netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
      4 193.95.80.35
      3 46.101.235.31
      1 66.249.93.63
      1 66.249.65.210
      1 66.249.65.208

Note:
Above command is very useful if your server is under attack and then you can block the IP. Also, you can change the port no as per your requirement.

Now let’s try to understand the command:

netstat -tn
netstat command will help you to list all the network in’s and out’s connection

-n: Display numeric only, don’t resolve into name.
-t: Display only TCP connections.

tcp        0      0 63.*.*.*:80             46.101.235.31:37361         TIME_WAIT
tcp        0      0 63.*.*.*:80             193.95.80.35:3393           TIME_WAIT
tcp        0     21 63.*.*.*:22             166.111.68.168:55022        ESTABLISHED
tcp        0      0 63.*.*.*:80             46.101.235.31:37277         TIME_WAIT
tcp        0      0 63.*.*.*:80             66.249.93.63:62556          TIME_WAIT
tcp        0      0 63.*.*.*:80             193.95.80.35:3397           TIME_WAIT
tcp        0      0 63.*.*.*:22             91.223.37.44:34648          TIME_WAIT

2>/dev/null
It will redirect all the unwanted output to /dev/null

grep :80
This will help to display the IP address those are connected to the server on port 80.

tcp        0      0 63.*.*.*:80             46.101.235.31:37361         TIME_WAIT
tcp        0      0 63.*.*.*:80             193.95.80.35:3393           TIME_WAIT
tcp        0      0 63.*.*.*:80             46.101.235.31:37277         TIME_WAIT
tcp        0      0 63.*.*.*:80             66.249.93.63:62556          TIME_WAIT
tcp        0      0 63.*.*.*:80             193.95.80.35:3397           TIME_WAIT

awk ‘{print $5}’
awk command will help to display the 5th field.

66.249.65.208:57679
46.101.235.31:54495
5.8.182.221:49609
5.8.182.221:31772
5.8.182.221:10597
195.87.49.10:43415
46.101.235.31:54404

cut -d: -f1
Uses cut to extract the content.

-d: Character immediately following the -d option is use as delimiter, default is tab.
-f: Specifies a field list, separated by a delimiter.

66.249.65.208
46.101.235.31
5.8.182.221
5.8.182.221
5.8.182.221
195.87.49.10
46.101.235.31

sort
Sort the list in reverse order.

110.174.54.188
216.104.200.9
216.104.200.9
217.153.116.4
46.101.235.31
46.101.235.31
46.101.235.31
46.101.235.31
66.249.65.210

uniq -c
It will make group of sorted list

1 212.145.147.225
2 217.73.208.150
4 46.101.235.31
1 66.249.65.210

sort -nr
It will sort by numeric, and reverse order (highest display first)

4 46.101.235.31
2 217.73.208.150
2 178.62.134.179
1 63.142.253.205
1 212.145.147.225

head
This is optional, to display the first 10 result.

4 46.101.235.31
2 178.62.134.179
1 63.142.253.205
1 217.73.208.150
1 202.12.102.10

Enjoy it!

No Responses

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.