Category Archives: linux

Shell Script to Detect If the IP Address Is Googlebot

Recently I wanted to check if the IPs ( I had around 45) belonged to google bot. One option was to run host <ip> and host <domain name> for each of the IPs, but this was practically not possible and if possible it would be time consuming. So I came up with a simple shell script to do this job.

Let the IPs be in the file googlebots, for example let us add these IPs:

66.249.66.246
66.249.66.97
66.249.64.12

The shell script is given below:

#!/bin/sh
file="googlebots"
while read -r line
do
    hostName=`host $line | cut -d" " -f 5`
    domainName=`echo $hostName | cut -d"." -f2,3`
    #echo $domainName
    #echo "$hostName"
    hostIp=`host $hostName | cut -d" " -f 4`
    #echo "$hostIp"
    if [ $line == $hostIp ] && [ $domainName == "googlebot.com" ]
    then
        echo "Googlebot: $hostIp -> $hostName"
    fi
done < "$file"
Advertisements