-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
191 lines (152 loc) · 3.92 KB
/
Makefile
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/bmake
#
# 20190130 Kimmo Suominen
#
.PHONY: default
default: all
COUNTRY_LIST = fi cn ru
ISP_LIST != "${.CURDIR}/isp2asn" LIST
GCP_REGIONS = us-east1 europe-north1
DESTDIR = ${HOME}/src/cloud/ansible/files
ROUTES = routes
NETWORKS = networks
.SUFFIXES: -asn -inet -inet6 .country.json .routes.json
.PHONY: all install summary
summary: isp-summary
.PHONY: isp-summary
isp-summary:
@"${.CURDIR}/isp2asn" SUMMARY
.for i in ${COUNTRY_LIST}
all: country-${i}-asn country-${i}-inet country-${i}-inet6
country-${i}.country.json:
curl -LSs "$$( \
echo \
https://stat.ripe.net/data/ \
country-resource-list \
/data.json?resource= \
$$( \
echo "${i}" \
| tr '[:lower:]' '[:upper:]' \
) \
| tr -d '[:space:]' \
)" > "${.TARGET}"
summary: country-${i}-summary
country-${i}-summary:
@echo
@wc -l country-"${i}"-asn
@echo
@wc -l country-"${i}"-inet* | sort -nr
.endfor
.for i in ${ISP_LIST}
all: routes-${i}-inet routes-${i}-inet6
routes-${i}.routes.json:
curl -LSs "$$( \
echo \
https://stat.ripe.net/data/ \
announced-prefixes \
/data.json?resource= \
$$(${.CURDIR}/isp2asn "${i}") \
| tr -d '[:space:]' \
)" > "${.TARGET}"
install: ${DESTDIR}/${ROUTES}/routes-${i}-inet
${DESTDIR}/${ROUTES}/routes-${i}-inet: routes-${i}-inet
install -m 0640 ${.ALLSRC} ${.TARGET}
install: ${DESTDIR}/${ROUTES}/routes-${i}-inet6
${DESTDIR}/${ROUTES}/routes-${i}-inet6: routes-${i}-inet6
install -m 0640 ${.ALLSRC} ${.TARGET}
.endfor
summary: network-routes-summary
.PHONY: network-routes-summary
network-routes-summary:
@for type in network routes ; \
do \
for family in inet inet6 ; \
do \
echo ; \
wc -l "$${type}"-*-"$${family}" \
| sort -nr ; \
done ; \
done
.country.json-asn:
jq -r '.data.resources.asn[]' \
< "${.ALLSRC}" \
> "${.TARGET}"
.country.json-inet:
jq -r '.data.resources.ipv4[]' \
< "${.ALLSRC}" \
| while read line ; \
do \
case "$${line}" in \
*-*) \
ipcalc "$${line}" \
| sed -n '1n;p' \
;; \
*) \
echo "$${line}" \
;; \
esac \
done \
| "${.CURDIR}/cidr.py" \
> "${.TARGET}"
.country.json-inet6:
jq -r '.data.resources.ipv6[]' \
< "${.ALLSRC}" \
| "${.CURDIR}/cidr.py" \
> "${.TARGET}"
.routes.json-inet:
jq -r '.data.prefixes[].prefix' \
< "${.ALLSRC}" \
| fgrep -v ':' \
| "${.CURDIR}/cidr.py" \
> "${.TARGET}"
.routes.json-inet6:
jq -r '.data.prefixes[].prefix' \
< "${.ALLSRC}" \
| fgrep ':' \
| "${.CURDIR}/cidr.py" \
> "${.TARGET}"
# Obtain Google IP address ranges
# https://support.google.com/a/answer/10026322
#google-all.json:
# curl -LSs https://www.gstatic.com/ipranges/goog.json > "${.TARGET}"
google-cloud.json:
curl -LSs https://www.gstatic.com/ipranges/cloud.json > "${.TARGET}"
.for i in ${GCP_REGIONS}
all: network-gcp-${i}-inet
network-gcp-${i}-inet: google-cloud.json
jq -r --arg region "${i}" '.prefixes[] | select(.scope == $$region) \
| select(.ipv4Prefix != null) | .ipv4Prefix' "${.ALLSRC}" \
> "${.TARGET}"
all: network-gcp-${i}-inet6
network-gcp-${i}-inet6: google-cloud.json
jq -r --arg region "${i}" '.prefixes[] | select(.scope == $$region) \
| select(.ipv6Prefix != null) | .ipv6Prefix' "${.ALLSRC}" \
> "${.TARGET}"
#install: ${DESTDIR}/${NETWORKS}/network-gcp-${i}-inet
#${DESTDIR}/${NETWORKS}/network-gcp-${i}-inet: network-gcp-${i}-inet
# install -m 0640 ${.ALLSRC} ${.TARGET}
#install: ${DESTDIR}/${NETWORKS}/network-gcp-${i}-inet6
#${DESTDIR}/${NETWORKS}/network-gcp-${i}-inet6: network-gcp-${i}-inet6
# install -m 0640 ${.ALLSRC} ${.TARGET}
.endfor
.PHONY: clean
clean:
rm -f \
country-*-asn \
country-*-inet \
country-*-inet6 \
network-gcp-*-inet \
network-gcp-*-inet6 \
routes-*-inet \
routes-*-inet6 \
.PHONY: cleanjson
cleanjson:
rm -f \
country-*.country.json \
google-cloud.json \
routes-*.routes.json \
.PHONY: refresh
refresh: cleanjson all
.PHONY: list-targets
list-targets:
@echo ${.ALLTARGETS} | tr ' ' '\n'