Posts Tagged ‘my IP’

Ignore my IP in AWStats

Sunday, June 29th, 2008

I use AWStats to get statistical usage information about my websites. The problem is that for less important websites like my private one I often test and develop directly on the production system. That creates many garbage entries in the HTTP log.

AWStats has the option SkipHosts for the configuration file, but my IP changes all the time.

So what I did was this:

Modify awstats.pl

...
if ($param =~ /^SkipHosts/) {
    @SkipHosts=();
        #foreach my $elem (split(/\s+/,$value)) {
        #       if ($elem =~ /^REGEX\[(.*)\]$/i) { $elem=$1; }
        #       else { $elem='^'.quotemeta($elem).'$'; }
        #       if ($elem) { push @SkipHosts, qr/$elem/i; }
        #}
        ####
        my $ips="/home/whoever/ips.txt";
        open(DAT, $ips) || die("can't open ip list");
        my @lines=<DAT>;
        close(DAT);
        foreach my $line (@lines)
        {
                chop($line);
                my $esc='^'.quotemeta($line).'$';
                push @SkipHosts, qr/$esc/i;
        }
        ####
        next;
        }
...

(You may want to keep the old code which I commented out and concatenate it with your values for @SkipHosts.)

Log my IPs

How that can be done depends on the situation. In my case I can safely assume that I have logged in to the web server over ssh with most IPs that I would use, so I added this to the .bash_profile:

echo $SSH_CLIENT | egrep -i -o '([[:digit:]]+\.){3}[[:digit:]]+' >> ips.txt

Hope it helps someone.