Last active
February 15, 2022 01:19
-
-
Save jpigla/10ba4ed9c418effeaba3dcef13bb1fa9 to your computer and use it in GitHub Desktop.
Philipps Collection of Python Functions
This file contains hidden or 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
# /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/philipps_module.py | |
# get latest ip addresses for google bot and bing bot (15.02.2022) | |
# https://gist.github.com/eliasdabbas/169cc580f8d10a63d5a5d3df04ef9758 | |
def get_bot_ip_addresses(): | |
""" | |
get latest ip addresses for google bot and bing bot | |
""" | |
import ipaddress | |
import requests | |
import pandas as pd | |
bots_urls = { | |
'google': 'https://developers.google.com/search/apis/ipranges/googlebot.json', | |
'bing': 'https://www.bing.com/toolbox/bingbot.json' | |
} | |
ip_addresses = [] | |
for bot, url in bots_urls.items(): | |
bot_resp = requests.get(url) | |
for iprange in bot_resp.json()['prefixes']: | |
network = iprange.get('ipv4Prefix') | |
if network: | |
ip_list = [(bot, str(ip)) for ip in ipaddress.IPv4Network(network)] | |
ip_addresses.extend(ip_list) | |
return pd.DataFrame(ip_addresses, columns=['bot_name', 'ip_address']) | |
# get domain name from ip address (15.02.2022) | |
def dns_lookup(ip_address): | |
""" | |
get domain name from ip address | |
""" | |
import socket | |
domain_name = socket.gethostbyaddr(ip_address)[0] | |
return str(domain_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment