Get uniqe IPs from apache access log

Apache log files

Apache logs everything that is going on with the server. The two intersting files are errlr.log and access.log. I'm goig to use the access.log fil, to get uniqe IP's, that's been visiting my side.

Open a terminal, I use the shortkey ctrl + alt + t. Then cd down to the log dir:

cd /var/log/apache2

Then check that the files are there:

ls -la

OK, files are there, that's good. Now we're going to use the cat command. cat To raw print that file, enter:

cat access.log

Now to get all the IPs, write:

cat access.log | cut -d ' ' -f 1

This gives you a list of all the IPs in the access file. This is basically all your hits. To get the number of hit, you'll just count the IPs, with wc -l

cat access.log | cut -d ' ' -f 1 | wc -l

Now you'll just get a number. But wait... That's all the IPs. What if you want to know the unique IPs? Type in:

cat access.log | cut -d ' ' -f 1 | sort | uniq

This will list all the IPs, but only one time. To get the count of that just add | wc -l

cat access.log | cut -d ' ' -f 1 | sort | uniq | wc -l

Now you'll just get a number, and that number is the unique IPs that's been visiting your site.

blogroll

social