Skip to content

Instantly share code, notes, and snippets.

@serge-larin
Last active May 22, 2023 06:14
Show Gist options
  • Save serge-larin/aaab0649fa307e3a7f70f12e9b88bfa0 to your computer and use it in GitHub Desktop.
Save serge-larin/aaab0649fa307e3a7f70f12e9b88bfa0 to your computer and use it in GitHub Desktop.
Get network list by country
#!/bin/bash
if [ -z "$1" ]; then
COUNTRY="ru"
else
COUNTRY=$1
fi
PATTERN=${COUNTRY^^}$
BATCH=50
I=0
ASN_LIST=""
(for ASN in `/usr/bin/curl -Ss https://ftp.ripe.net/ripe/asnames/asn.txt|grep $PATTERN | cut -d " " -f 1`; do
((I++))
ASN_LIST="$ASN_LIST AS$ASN"
if [ $I == $BATCH ]; then
/usr/bin/bgpq3 -Ab $ASN_LIST | egrep -o '[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/[0-9]+'
I=0
ASN_LIST=""
fi
done
if [ -n "$ASN_LIST" ]; then
/usr/bin/bgpq3 -Ab $ASN_LIST | egrep -o '[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/[0-9]+'
fi
) | sort -n | uniq | /usr/bin/aggregate -q > /tmp/$COUNTRY-net.lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment