Blog Linux

how to get ip addresses accessing your website

Got this one from Donncha on his Who’s abusing your website?

grep -v "wp-content" access.log|grep -v wp-includes|cut -f 1 -d " "|sort|uniq -c|sort -nr|less

Hmnn.. pretty neat, noh? It will list down all IP addresses that accessed your website including the number of appearance (how many times the site was accessed by the IP).

Here's what Donncha says about this code.

* Excludes “wp-content” and “wp-includes” requests.
* Uses “cut” to cut out the IP address.
* Sorts the list of IP addresses.
* Uses “uniq” to count the occurrence of each IP.
* And finally reverse sorts the list again, by number of occurrences, with the largest number at the top.

By the way, I like the titleof Donncha's blog -- "Holy Shmoly! Look what I found today!". That pretty much sums up my own blog, eh?