nerdegutta.no
Get unique IPs from Apache access log
20.12.23
Miscellaneous
Apache log files
Apache logs everything that is going on with the web server. The two interesting files are error.log and access.log. I'm going to use the access.log file to get the unique IP's thats been visiting my site.
Open a terminal, I use the shortcut CTRL + ALT + Delete. Then I cd down to the log dir:
cd /var/log/apache2
To check that the files are there:
ls -la
OK, the files are there, that's good. Now we're going to use the cat command. This will rawprint the file to the screen:
cat access.log
Now, to get all the IPs, enter:
cat access.log | cut -d'' -f 1
This will give you a list of all the IPs in the access.log-file. This is basically all your hits. To get the number of hits, you'll just count the IPs. Add wc -l to the command.
cat access.log | cut -d'' -f 1 | wc -l
Now you'll just have a number. But wait... That's all the IPs. What if you want to know the unique number of IPs? No problem. This will get all the unique IPs.
cat access.log | cut -d'' -f 1 | sort | uniq
The list that runs over you screen is all the unique hits. The get the numbers:
cat access.log | cut -d'' -f 1 | sort | uniq | wc -l
Now you'll just get a number, and that's the number of unique hits on your web server.