Perl code to detect googlebot from CGI
This routine detects Googlebot under a CGI environment. It also tests the remote address to make sure that the remote user really is from Google.
# In a CGI environment, this returns 1 if the remote user is # googlebot, and undefined otherwise. sub detect_googlebot { my $user_agent = $ENV{HTTP_USER_AGENT}; if ($user_agent =~ /googlebot/i) { my $remote_addr = $ENV{REMOTE_ADDR}; if ($remote_addr =~ /^66\.249\./ || $remote_addr =~ /^72\.14\./ || $remote_addr =~ /^74\.125\./ || $remote_addr =~ /^209\.85\./ # Use the following line to debug this. # || $remote_addr =~ /^192\.168\./ ) { return 1; } } return; }
Copyright © Ben Bullock 2009-2024. All
rights reserved.
For comments, questions, and corrections, please email
Ben Bullock
(benkasminbullock@gmail.com).
/
Privacy /
Disclaimer