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:

The shell script is given below:

while read -r line
    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 == "" ]
        echo "Googlebot: $hostIp -> $hostName"
done < "$file"