Last active
July 25, 2019 11:48
-
-
Save hamletbatista/847687ca4d556feabd7aa47efbafe008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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