Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Last active July 25, 2019 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamletbatista/847687ca4d556feabd7aa47efbafe008 to your computer and use it in GitHub Desktop.
Save hamletbatista/847687ca4d556feabd7aa47efbafe008 to your computer and use it in GitHub Desktop.
import socket
def verify_googlebot(bot_ip):
try:
host = socket.gethostbyaddr(bot_ip)
bot_name = host[0]
except:
#no PTR record
#print(bot_ip)
return False
if bot_name.find("googlebot.com") < 0:
return False
try:
ip = socket.gethostbyname(bot_name)
except:
#no A record
#print(bot_name)
return False
return bot_ip == ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment