DPR-blocked-sites/is_google_subnet.py

19 lines
451 B
Python
Raw Normal View History

import ipaddress
import requests
import json
x = input()
res = requests.get('https://www.gstatic.com/ipranges/goog.json')
response = json.loads(res.text)
ipv4Prefix = [x['ipv4Prefix'] for x in filter(lambda x: 'ipv4Prefix' in x, response["prefixes"])]
for prefix in ipv4Prefix:
isInPrefix = ipaddress.ip_address(x) in ipaddress.ip_network(prefix)
if isInPrefix:
print(x, 'is subnet of', prefix)
exit()
print('not found')