aboutsummaryrefslogtreecommitdiff
path: root/utils/google6.py
diff options
context:
space:
mode:
authorPetr <30545094+pasabanov@users.noreply.github.com>2024-07-17 12:00:42 +0300
committerGitHub <noreply@github.com>2024-07-17 11:00:42 +0200
commit0a3a82680d6171a005fa944916ef551b4c3aafa7 (patch)
tree8b26a4681b6aaac1626a07473e58d151cd44a72a /utils/google6.py
parent989dde1a40f9303f0e6331141f6433fd1b4ef5d9 (diff)
python: reformatted, fixed bugs (#2504)
Diffstat (limited to 'utils/google6.py')
-rwxr-xr-x[-rw-r--r--]utils/google6.py65
1 files changed, 34 insertions, 31 deletions
diff --git a/utils/google6.py b/utils/google6.py
index 2d9ffa27c..a09580a10 100644..100755
--- a/utils/google6.py
+++ b/utils/google6.py
@@ -4,38 +4,41 @@ import json
import urllib.request
import netaddr
-GOOG_URL="https://www.gstatic.com/ipranges/goog.json"
-CLOUD_URL="https://www.gstatic.com/ipranges/cloud.json"
+GOOG_URL = "https://www.gstatic.com/ipranges/goog.json"
+CLOUD_URL = "https://www.gstatic.com/ipranges/cloud.json"
+
def read_url(url):
- try:
- s = urllib.request.urlopen(url).read()
- return json.loads(s)
- except urllib.error.HTTPError:
- print("Invalid HTTP response from %s" % url)
- return {}
- except json.decoder.JSONDecodeError:
- print("Could not parse HTTP response from %s" % url)
- return {}
+ try:
+ s = urllib.request.urlopen(url).read()
+ return json.loads(s)
+ except urllib.request.HTTPError:
+ print("Invalid HTTP response from %s" % url)
+ return {}
+ except json.decoder.JSONDecodeError:
+ print("Could not parse HTTP response from %s" % url)
+ return {}
+
def main():
- goog_json=read_url(GOOG_URL)
- cloud_json=read_url(CLOUD_URL)
-
- if goog_json and cloud_json:
-# print("{} published: {}".format(GOOG_URL,goog_json.get('creationTime')))
-# print("{} published: {}".format(CLOUD_URL,cloud_json.get('creationTime')))
- goog_cidrs = netaddr.IPSet()
- for pref in goog_json['prefixes']:
- if pref.get('ipv6Prefix'):
- goog_cidrs.add(pref.get('ipv6Prefix'))
- cloud_cidrs = netaddr.IPSet()
- for pref in cloud_json['prefixes']:
- if pref.get('ipv6Prefix'):
- cloud_cidrs.add(pref.get('ipv6Prefix'))
-# print("IP ranges for Google APIs and services default domains:")
- for i in goog_cidrs.difference(cloud_cidrs).iter_cidrs():
- print(i)
-
-if __name__=='__main__':
- main()
+ goog_json = read_url(GOOG_URL)
+ cloud_json = read_url(CLOUD_URL)
+
+ if goog_json and cloud_json:
+ # print("{} published: {}".format(GOOG_URL,goog_json.get('creationTime')))
+ # print("{} published: {}".format(CLOUD_URL,cloud_json.get('creationTime')))
+ goog_cidrs = netaddr.IPSet()
+ for pref in goog_json['prefixes']:
+ if pref.get('ipv6Prefix'):
+ goog_cidrs.add(pref.get('ipv6Prefix'))
+ cloud_cidrs = netaddr.IPSet()
+ for pref in cloud_json['prefixes']:
+ if pref.get('ipv6Prefix'):
+ cloud_cidrs.add(pref.get('ipv6Prefix'))
+ # print("IP ranges for Google APIs and services default domains:")
+ for i in goog_cidrs.difference(cloud_cidrs).iter_cidrs():
+ print(i)
+
+
+if __name__ == '__main__':
+ main()