-1

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.

Dan
  • 101
  • 1

2 Answers2

3

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.

#!/bin/bash

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

Use it as such:

cut -f 1 -d ' ' access.log | sort | uniq | ips.sh
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Sorry for asking this. I am pretty new with terminal commands and shell. I copied the script above in ips.sh and typed in the cut statement as shown. Am I doing it right? – Dan Sep 04 '13 at 11:34
  • Did you do `chmod +x ips.sh` ? You need to specify execution permissions – Alex Sep 04 '13 at 11:36
  • yes I did a chmod. It tells me "ips.sh: command not found" – Dan Sep 04 '13 at 11:39
-1

If you are using Windows you can parse the concatenated log file with a script, performing "nslookup" on each IP.

if wscript.arguments.count > 0
then
  logname = wscript.arguments(0)
  set fs = wscript.createobject("scripting.filesystemobject")
  set readstream = fs.opentextfile(logname, 1, 0, 0)
  while not readstream.atendofstream str = readstream.readline ' parse str with RegEx object to get IP
    set shell = wscript.createobject("wscript.shell")
    shell.run "nslookup " & ip & " > temp.txt", 0
    set lookupstream = fs.opentextfile("temp.txt", 1, 0, 0)
    lookup = lookupstream.readall ' parse lookup info
    lookupstream.close
  wend
  readstream.close
Ladadadada
  • 26,337
  • 7
  • 59
  • 90
  • @MichaelHampton `if wscript.arguments.count > 0 then logname = wscript.arguments(0) set fs = wscript.createobject("scripting.filesystemobject") set readstream = fs.opentextfile(logname, 1, 0, 0) while not readstream.atendofstream str = readstream.readline ' parse str with RegEx object to get IP set shell = wscript.createobject("wscript.shell") shell.run "nslookup " & ip & " > temp.txt", 0 set lookupstream = fs.opentextfile("temp.txt", 1, 0, 0) lookup = lookupstream.readall ' parse lookup info lookupstream.close wend readstream.close` – Vladimir Tsuverkalov Sep 04 '13 at 10:52
  • @VladimirTsuverkalov I added the script from your comments to the answer but it looks incomplete. Did the comment box cut off the end of the script? – Ladadadada Sep 04 '13 at 12:11
  • @Ladadadada I was just posting a general outline of a script, skipping parts that do the parsing itself. If it's desired, I can edit them in a bit later – Vladimir Tsuverkalov Sep 04 '13 at 12:30