forked from Loyalsoldier/geoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asn.sh
executable file
·23 lines (20 loc) · 988 Bytes
/
asn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash
input="./asn.csv"
mkdir -p ./tmp ./data
while IFS= read -r line; do
filename=$(echo ${line} | awk -F ',' '{print $1}')
IFS='|' read -r -a asns <<<$(echo ${line} | awk -F ',' '{print $2}')
file="data/${filename}"
echo "==================================="
echo "Generating ${filename} CIDR list..."
rm -rf ${file} && touch ${file}
for asn in ${asns[@]}; do
url="https://stat.ripe.net/data/ris-prefixes/data.json?list_prefixes=true&types=o&resource=${asn}"
echo "-----------------------"
echo "Fetching ${asn}..."
curl -sL ${url} -o ./tmp/${filename}-${asn}.txt \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'
jq --raw-output '.data.prefixes.v4.originating[]' ./tmp/${filename}-${asn}.txt | sort -u >>${file}
jq --raw-output '.data.prefixes.v6.originating[]' ./tmp/${filename}-${asn}.txt | sort -u >>${file}
done
done <${input}