How to check the concurrent Apache connections and IP address of the remote host?
Mobile App Developer with over a decade of coding expertise. Passionate about building innovative products to solve real-world problems and enhance user experience.
This command is using several command line utilities to gather information about the current network connections on a Linux or Unix-based system.
netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r
netstat -ntu: Thenetstatcommand is used to display network statistics. The option-ncauses it to display numerical addresses instead of trying to determine host names,-tlimits the display to TCP connections, and-ulimits the display to UDP connections.awk '{print $5}':awkis a text-processing tool. This command usesawkto print the 5th field of the output from thenetstatcommand. The fields are separated by spaces, so this will print the IP address of the remote host for each connection.cut -d: -f1 -s:cutis used to remove sections from each line of input. This command is usingcutto remove the colon and everything after it from each IP address, resulting in the IP address of the remote host without the port number.sort: Thesortcommand is used to sort the list of IP addresses in lexicographic order.uniq -c:uniqcommand is used to filter out repeating lines in a file. The option-ccauses it to prefix each line of output with the number of times it occurred in the input.sort -nk1 -r: Thesortcommand is used again, this time sorting the list of IP addresses in descending order by the number of occurrences. The option-ncauses it to sort numerically,-k1sort on the first field, and-rsort in reverse order (i.e. descending).
The output of this command:
# netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq - c|sort -nk1 -r
13 158.158.56.141
11 178.158.56.142
10 169.158.56.140
8 122.158.56.143
5 111.234.242.60
1 198.70.251.44
