-
-
Save ShakataGaNai/f2a6538f5a6c8081e04b54ed073f0c34 to your computer and use it in GitHub Desktop.
Google Cloud Platform : ip address range
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
#!/usr/local/bin/python3.6 | |
import dns.resolver | |
import re | |
def main(): | |
v4 = [] | |
v6 = [] | |
v4, v6 = que('_cloud-netblocks.googleusercontent.com') | |
for o4 in v4: | |
print(o4) | |
for o6 in v6: | |
print(o6) | |
def que(netblock): | |
v4 = [] | |
v6 = [] | |
resr = dns.resolver.Resolver() | |
resr.nameservers = ['8.8.8.8'] | |
ans = resr.query(netblock,'TXT') | |
pi = re.compile('include:(.*?)\s',re.IGNORECASE) | |
p4 = re.compile('ip4:(.*?)\s',re.IGNORECASE) | |
p6 = re.compile('ip6:(.*?)\s',re.IGNORECASE) | |
for line in ans: | |
st = line.to_text() | |
for a in pi.findall(st): | |
a4, a6 = que(a) | |
v4.extend(a4) | |
v6.extend(a6) | |
v4.extend(p4.findall(st)) | |
v6.extend(p6.findall(st)) | |
return(v4, v6) | |
main() |
It seems to require the dnspython
package.
I've made a Github repo with an updated list :
https://github.com/pierrocknroll/googlecloud-iprange
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked from the original to support recursive includes, along with IPv6 Ranges. Output as of 2018-03-12: