apache: show most frequest IPs from log file

There are times when you doubt that something strange is happening with your site. You might be suspecting some kind of attack. Apache logs can help you to quickly summarize number of requests coming from various IP addresses.

Following command will display 20 IP addresses that were accessing your website most frequently, sorted so that most frequent are on top.

cat path-to-log-file.log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20

Notes:

  1. Apache log files are usually located in /var/log/apache2
  2. This won’t help if you have a reverse proxy in front of your website, then almost all requests will be coming from IP address of the reverse proxy
Share

Recent Posts

CSS: Height equal to dynamic width

There is a way using CSS! If you set your width depending on the parent…

3 years ago

bash: Find text in files in subdirectories recursively

grep -rnw '/path/to/somewhere/' -e 'pattern' -r or -R is recursive, -n is line number, and -w stands for match the…

7 years ago

Remove duplicate lines from text file

This snippet will remove duplicate lines from text file: awk '!seen[$0]++' filename It will display…

8 years ago

phpMyAdmin: Different SQL file name on each export

Easiest way to export your database is through phpMyAdmin. With few clicks you can get…

10 years ago

Restart Apache automatically

Put this code into a .sh file, add executable permissions to it and add it…

10 years ago

Restart MySQL automaticaly

Put this code into a .sh file, add executable permissions to it and add it…

10 years ago