Skip to content

Instantly share code, notes, and snippets.

@merty
Last active March 19, 2021 17:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merty/57a4c272afbc38a0a79128f718a80f62 to your computer and use it in GitHub Desktop.
Save merty/57a4c272afbc38a0a79128f718a80f62 to your computer and use it in GitHub Desktop.
Performs reverse and forward DNS lookups to list Googlebot's IPs, given a list of IP addresses as a file. Useful for filtering access logs to find out actual Googlebot visits. An implementation of https://support.google.com/webmasters/answer/80553?hl=en
#/bin/bash
#
# Performs reverse and forward DNS lookups to list Googlebot's IPs, given a list
# of IP addresses as a file. Useful for filtering access logs to find out actual
# Googlebot visits.
#
# An implementation of https://support.google.com/webmasters/answer/80553?hl=en
while IFS='' read -r IP_ADDRESS || [[ -n "$IP_ADDRESS" ]];
do
IS_GOOGLEBOT=0
REVERSE_LOOKUP="$(host $IP_ADDRESS)"
echo "$REVERSE_LOOKUP" | grep -E "google.com.$|googlebot.com.$" > /dev/null && IS_GOOGLEBOT=1
if [[ IS_GOOGLEBOT -eq 1 ]]; then
FORWARD_LOOKUP="$(host $(echo "$REVERSE_LOOKUP" | cut -d " " -f 5) | cut -d " " -f 4)"
if [[ "$FORWARD_LOOKUP" = "$IP_ADDRESS" ]];
then
echo $IP_ADDRESS
fi
fi
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment