Get domain names from IP addresses from access.log

Dan asked:

Actually I want to see people from which domain access my website. I want to generate the domain names from IP addresses in the Apache access.log file.

How can I do this? There are around 54 log files. I concatenate all the files into one.

This is a Unix server. I have to use a apache log file analyzer. So i use webalizer but it is does not resolve IP to domain names.

My answer:

I wrote a simple script for this a long while back. It’s less than perfect and has a few failure modes, but does well enough for casual inspection. I’ve never been bothered to improve it, but perhaps someone else will.


while read junk
        echo -n "$junk "
        dig +short -x $junk

Use it as such:

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

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.