-
Notifications
You must be signed in to change notification settings - Fork 8
/
get-google-ips.py
45 lines (38 loc) · 1.43 KB
/
get-google-ips.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import json
import codecs
from IPy import IPSet, IP
r = requests.get('https://www.gstatic.com/ipranges/goog.json')
data = []
data.append(json.loads(r.text))
file_object = codecs.open('google-ip-ranges-'+data[0]['creationTime'][0:10]+'.txt', 'w' ,"utf-8")
for ip_ranges in data[0]['prefixes']:
#print(ip_ranges['ipv4Prefix'])
try:
file_object.write('/ip fir add add add='+ip_ranges['ipv4Prefix']+' comment="GOOGLE LLC '+data[0]['creationTime'][0:10]+'" list=dst-use-vpn'+"\r\n")
except:
try:
file_object.write('/ipv6 fir add add add='+ip_ranges['ipv6Prefix']+' comment="GOOGLE LLC '+data[0]['creationTime'][0:10]+'" list=dst-use-vpn'+"\r\n")
except:
pass
r = requests.get('https://www.gstatic.com/ipranges/cloud.json')
data = []
data.append(json.loads(r.text))
ret = IPSet()
for ip_ranges in data[0]['prefixes']:
try:
curip=ip_ranges['ipv4Prefix']
ret.add(IP(curip, make_net = True))
except:
try:
file_object.write('/ipv6 fir add add add='+ip_ranges['ipv6Prefix']+' comment="GOOGLE Cloud '+data[0]['creationTime'][0:10]+'" list=dst-use-vpn'+"\r\n")
except:
pass
for ip_ranges in ret:
try:
file_object.write('/ip fir add add add='+ip_ranges.strNormal()+' comment="GOOGLE Cloud '+data[0]['creationTime'][0:10]+'" list=dst-use-vpn'+"\r\n")
except:
# do nothing
pass
file_object.close()
print('success! file '+'google-ip-ranges-'+data[0]['creationTime'][0:10]+'.txt')