Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Get list of all unique IP Addresses connected to your server

Mike Peters, 02-27-2010
Want to find out if your server is under DoS attack?

Or maybe you want to optimize your architecture, understanding the network footprint of each of your servers?

Using a combination of handy shell commands, it's easy to construct a list of all IP addresses connected to your server, sorted by count:

On FreeBSD:
netstat -nat | sed -n -e '/ESTABLISHED/p' | awk '{print $5}' | sed 's/\./ /g' | awk '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -n

On Linux:
netstat -ntu | sed -e 's/::ffff://g' | awk '{print $5}' | cut -d : -f1 | sort | uniq -c | sort -n

Sample output:

1 114.56.110.115
1 114.56.110.90
1 67.128.224.129
2 114.56.110.85
4 114.56.110.99
5 208.53.167.125
7 67.128.224.128
14 114.56.110.116
15 114.56.110.125
18 114.56.110.84

Blocking offenders is as easy as:

On Linux:
/sbin/iptables -I INPUT -s 114.56.110.84 -j DROP

On FreeBSD:
echo "ALL : 114.56.110.84 : deny" >> /etc/hosts.allow

Mike Peters, 03-23-2010
Here's how to get a list of all file descriptors by process:

lsof | awk '{print $1}' | sort | uniq -c | sort -n

mba, 06-10-2010
Admiring the time and effort you put into your blog and detailed information you offer!

hiwaar, 06-25-2010
Thanks for the valubale information

Mike Peters, 07-29-2010
Thanks @mba

For anyone using Java, this line is useful - shows how many times each JAR is open:

lsof | grep java | awk '{print $NF}' | sort | uniq -c | sort -n | tail
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions