Last active
May 22, 2023 06:14
-
-
Save serge-larin/aaab0649fa307e3a7f70f12e9b88bfa0 to your computer and use it in GitHub Desktop.
Get network list by country
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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