DPR-blocked-sites/is_google_subnet.py
Maxim Slipenko b748fb1c96 Добавляет IP-диапазоны Google (#1)
Co-authored-by: Maxim Slipenko <no-reply@maxim.slipenko.com>
Reviewed-on: #1
2022-09-16 15:15:04 +00:00

19 lines
451 B
Python

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')