Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I get some stats on unique IPv4 and IPv6 visitors by looking at a nginx access.log with UNIX CLI?

I use the standard combined pre-defined format for access_log.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

To get a summary on the number of unique IPv4 and IPv6 visitors in the last two days:

grep "1[89]/Feb/" /var/www/logs/mdoc.su/mdoc.su.access.log | \
cut -d " " -f1 | sort | uniq | sed "s#.*\..*#.#g;s#.*:.*#:#g" | \
sort | uniq -c ; echo ipv4 and ipv6 unique hosts, summary ; date

To get a summary on the number of unique IPv4/24 and IPv6/48 subnets of the unique visitors in the last two days:

grep "1[89]/Feb/" /var/www/logs/mdoc.su/mdoc.su.access.log | \
cut -d " " -f1 | sort | uniq | sed -E "s#^(([0-9a-f]+[.:]){3}).*#\1#g" | \
uniq | sed "s#.*\..*#.#g;s#.*:.*#:#g" | sort | uniq -c ; \
echo ipv4 and ipv6 unique IPv4/24 and IPv6/48 subnets, summary ; date

To see the most popular IPv4 and IPv6 subnets of the unique visitors in the last two days:

grep "1[89]/Feb/" /var/www/logs/mdoc.su/mdoc.su.access.log | \
cut -d " " -f1 | sort | uniq | sed -E "s#^(([0-9a-f]+[.:]){3}).*#\1#g" | \
uniq -c | sort -rn | head -16 ; \
echo ipv4 and ipv6 unique IPv4/24 and IPv6/48 nets, most popular nets ; date
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.