≡ Menu

Shell Script List All Top IP Address Accessing Apache / Lighttpd Web Server

How do I run this script?

Simply run it as follows:
./script nixcraft.com
Sample output (1st coloum is counter and 2nd is IP address):

You can block all spammers and content scrappers bots using Linux iptables or BSD pf firewall itself.

{ 9 comments… add one }
  • Ravi November 10, 2009, 11:02 am

    Can this SCript Send a mail with output?
    Can someone tell me how i can send a mail with above ip list.

  • joe August 11, 2009, 3:22 pm

    The sort on ip’s is alphabetic which is not quite right for looking at the numbered segments. so your script only works because the second sort is working on the count produced by uniq -c. Is the first sort even needed?

  • Mox July 17, 2009, 6:34 pm

    I think you should pipe the output of the report generating command to tail, otherwise you will get “every” address logged to your resulting report file. And the title of the script is top ip addresses accessing apache / lighthttpd not all unique ip addresses which is what your script is producing.

    Here a what i mean, with this you get the top 20 hitters only.
    awk ‘{ print $1}’ $LOGFILE | sort | uniq -c | sort -nr | tail -20 > $DEST/$DOM.txt

    • Saqib May 10, 2016, 5:03 pm

      Use “head” instead of tail, this way output shows only last 20 IP hit your website just one time.

      Top 20 IPs hits site multiple times.
      awk ‘{ print $1}’ $LOGFILE | sort | uniq -c | sort -nr | head -20 > $DEST/$DOM.txt

  • dsplabs June 22, 2009, 1:18 pm

    I use iptstate :)

  • Vivek Gite March 7, 2009, 7:29 pm

    Set LOGFILE variable. Usually, each server is configured with different location.

  • someone March 7, 2009, 1:30 pm

    hello when i stored it on my server i use this command:
    chmod +x ipcacher.sh
    and then when i try ./ipcacher.sh
    i dont see anything

    plz help me and reply my comment by sendig mail to me tnx

  • benim February 5, 2009, 6:32 pm

    hi ,

    i want to know, how i restart the script from zero or what is restart command..

    normally it begins from zero every midnight(00.00)


    best regards

  • kpb January 29, 2009, 9:20 pm

    Great script !! I made a script somewhat like this to check secure logs for failed ssh connections.
    Keep up the good work!

Security: Are you a robot or human?

Leave a Comment