Skip to content

Instantly share code, notes, and snippets.

@ShakataGaNai
Forked from n0531m/list_gcp_iprange.sh
Last active January 21, 2020 15:56
Show Gist options
  • Save ShakataGaNai/f2a6538f5a6c8081e04b54ed073f0c34 to your computer and use it in GitHub Desktop.
Save ShakataGaNai/f2a6538f5a6c8081e04b54ed073f0c34 to your computer and use it in GitHub Desktop.
Google Cloud Platform : ip address range
#!/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()
@pierrocknroll
Copy link

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