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
.
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