track ip addresses, lookup mac addresses, etc

Parsing Web Server Logs

Published January 02, 2017

This is assuming your webserver log is access.log.

Extract unique IP addresses from the webserver log:

cat access.log | awk '{print $1}' | uniq

Count number of unique IP addresses from log:

cat access.log | awk '{print $1}' | uniq | wc -l

List the IP addresses of users using iPhones:

cat access.log | grep -i iphone | awk '{print $1}' | uniq | sort

Count number of IP addresses of visitors who have a 444 error:

grep '444 0' access.log | awk '{print $1}' | sort -n | uniq -c | sort -n

List and sort user-agent strings uniquely:

awk -F"\"" '{print $6}' access.log | sort | uniq -dc | sort -nr

List top 25 IP addresses that have accessed my website:

awk '{print $1}' access.log | sort -n | uniq -c | sort -n | tail -25
{ % include 'ajrwd' %}

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Last Updated: January 02, 2017. Β Β Β  This post was originally written on June 01, 2009.

← Previous Post Bash script to reconnect Wi-Fi connection in Raspberry Pi

Python script to tweet your Internet speed Next Post β†’

{ % include 'footer' %}