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()
@ShakataGaNai
Copy link
Author

ShakataGaNai commented Mar 12, 2018

Forked from the original to support recursive includes, along with IPv6 Ranges. Output as of 2018-03-12:

35.230.0.0/17
35.230.128.0/18
35.230.192.0/19
35.230.224.0/20
35.231.0.0/16
130.211.4.0/22
8.34.208.0/20
8.35.192.0/21
8.35.200.0/23
108.59.80.0/20
108.170.192.0/20
108.170.208.0/21
108.170.216.0/22
108.170.220.0/23
108.170.222.0/24
162.216.148.0/22
162.222.176.0/21
173.255.112.0/20
192.158.28.0/22
199.192.112.0/22
199.223.232.0/22
199.223.236.0/23
23.236.48.0/20
23.251.128.0/19
35.224.0.0/14
35.228.0.0/15
107.167.160.0/19
107.178.192.0/18
146.148.2.0/23
146.148.4.0/22
146.148.8.0/21
146.148.16.0/20
146.148.32.0/19
146.148.64.0/18
35.203.0.0/17
35.203.128.0/18
35.203.192.0/19
35.203.240.0/20
130.211.8.0/21
130.211.16.0/20
130.211.32.0/19
130.211.64.0/18
130.211.128.0/17
104.154.0.0/15
104.196.0.0/14
208.68.108.0/23
35.184.0.0/14
35.188.0.0/15
35.206.64.0/18
35.202.0.0/16
35.190.0.0/17
35.190.128.0/18
35.190.192.0/19
35.190.224.0/20
35.192.0.0/14
35.196.0.0/15
35.198.0.0/16
35.199.0.0/17
35.199.128.0/18
35.200.0.0/15
35.204.0.0/15
2600:1900::/35

@Kentzo
Copy link

Kentzo commented Apr 18, 2018

It seems to require the dnspython package.

@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