7 goog_url
="https://www.gstatic.com/ipranges/goog.json"
8 cloud_url
="https://www.gstatic.com/ipranges/cloud.json"
12 s
= urllib
.request
.urlopen(url
).read()
14 except urllib
.error
.HTTPError
:
15 print("Invalid HTTP response from %s" % url
)
17 except json
.decoder
.JSONDecodeError
:
18 print("Could not parse HTTP response from %s" % url
)
22 goog_json
=read_url(goog_url
)
23 cloud_json
=read_url(cloud_url
)
25 if goog_json
and cloud_json
:
26 print("{} published: {}".format(goog_url
,goog_json
.get('creationTime')))
27 print("{} published: {}".format(cloud_url
,cloud_json
.get('creationTime')))
28 goog_cidrs
= netaddr
.IPSet()
29 for e
in goog_json
['prefixes']:
30 if e
.get('ipv4Prefix'):
31 goog_cidrs
.add(e
.get('ipv4Prefix'))
32 cloud_cidrs
= netaddr
.IPSet()
33 for e
in cloud_json
['prefixes']:
34 if e
.get('ipv4Prefix'):
35 cloud_cidrs
.add(e
.get('ipv4Prefix'))
36 print("IP ranges for Google APIs and services default domains:")
37 for i
in goog_cidrs
.difference(cloud_cidrs
).iter_cidrs():
40 if __name__
=='__main__':