hello, i use a simple log script on my site.. very basic..
i would like to modify it, and am having issues..
here is what i would like...
i would like to be able to have it filter out certian HOST names.. but not exact.. say for instance, i dont want it logging yahoo slurp.. the host name changes, but always ends in yahoo.com
so, i would like to filter out
and i would like to be able to add more than one, a list of filtered hosts, not IP's, that will not be logged..
so, i would like to change the $me var, to host, but not exact host, just domain (like i stated earlier) and then to create a list, by coma.
thanks a bunch
pj

here is the script:

#!/usr/bin/perl

$me = "38.117.78.220";  
$log = "/home/to/my/log.html";

#############################

if (!$ENV{'REMOTE_HOST'}) {my @subnet_numbers = split (/\./, $ENV{'REMOTE_ADDR'});
$ENV{'REMOTE_HOST'} = gethostbyaddr(pack("C4", @subnet_numbers), 2) || $ENV{'REMOTE_ADDR'};
	}

$ippjrey = $ENV{'REMOTE_ADDR'};
$hostpjrey = $ENV{'REMOTE_HOST'};
$privatepjrey = $ENV{'HTTP_X_FORWARDED_FOR'};

$getdate = `date +"%A %B %d, %Y, %r"`; 
chop ($getdate);


if ($ENV{'REMOTE_ADDR'} eq $me) {
   open (LOG, "$log");
   @lines = <LOG>;
   close (LOG);
   print "Content-type: text/html\n\n";
   open (LOG, ">$log");
   print LOG @lines;
   close (LOG);  

 

}
 
else {

   open (LOG, "$log");
   @lines = <LOG>;
   close (LOG);
   print "Content-type: text/html\n\n";
   open (LOG, ">$log");
    print LOG " [ <font size=-2 face=Verdana, Arial><B>Time:</B> $getdate ] </font>- \n";
    print LOG " [ <font size=-2 face=Verdana, Arial><B>With:</B> $ENV{'HTTP_USER_AGENT'} ]<BR></font>\n";
    print LOG " [ <font size=-2 face=Verdana, Arial color=red><B>Host: $ippjrey/$hostpjrey || [ $privatepjrey ] </B>]</font>\n";
    print LOG " [ <font size=-2 face=Verdana><B>From:</B> <font color=blue><A HREF=$ENV{'HTTP_REFERER'}>$ENV{'HTTP_REFERER'}</font></A></font>]<BR>\n";
    print LOG " [ <font size=-2 face=Verdana><B>Pages:</B> $here $ENV{'DOCUMENT_URI'} ]<BR><BR></font>\n\n";
   print LOG @lines;

   close (LOG);  

 

}
exit;

Dani AI

Generated

Short, practical addition: matching hostnames by domain suffix works best with a single anchored, case‑insensitive regex built from a comma‑separated list. restated the goal correctly and was on the right track with regexes, but the example there needs proper anchoring and escaping (and the =! in that post is a syntax mistake). The snippet below shows a safe, minimal way to replace the single $me check with a domain list that skips logging when the remote host ends in any listed domain.

# comma-separated domains to ignore (no wildcards, whitespace allowed)
my $ignore = 'yahoo.com, gmail.com, bad.example';

# build an anchored, case-insensitive regex that matches "yahoo.com" or any subdomain
my @domains = map { s/^\s+|\s+$//g; lc $_ } split /,/, $ignore;
my $alts = join '|', map { quotemeta($_) } grep { length } @domains;
my $skip_re = qr/(?:^|\.)(?:$alts)$/i;

# $host should come from REMOTE_HOST (or REMOTE_ADDR as fallback)
my $host = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR} || '';
if ($host =~ $skip_re) {
    # skip writing this request to the log
} else {
    # perform normal logging
}

Notes and troubleshooting: always log the IP regardless (reverse DNS can be absent or slow). Test patterns against real samples (print $host and the regex during testing). Use quotemeta (or \Q\E) to avoid accidental regex injection from the list. For noisy crawlers, matching User‑Agent strings or handling at the web‑server level is often faster than doing reverse lookups per request. This approach lets swap the single‑IP $me check for a flexible, comma‑separated host filter with minimal changes to the rest of the script.

Recommended Answers

All 5 Replies

anyone??

Sorry, I have read your question three times and I can't understand what you want to do.

Hey dude
Let me repharse ur question, Sorry if i understood wrong

If log is having

Then u like to have
only yahoo.com
gmail.com

is this u are looking for ?

Member Avatar for Member #356299

So I'm assuming you are looking for things that "end with" such and such,

that being the case a simple regular expression might do?

if ($line =~ m/)
{
if ($line =! m/^(www.|http:\/\/).)
{
print $line . "\n";
}

That line will basically take and do a search on anything containing
yahoo.com (case insensitive) then if it doesn't start with, www.yahoo.com, or http://yahoo.com
print the line out.

I'm not sure if that helps, hope it does

thanks, ill give it a try (major delay, i know.. never got the notification that you posted back)

thanks!
pj

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.