Skip to content

Instantly share code, notes, and snippets.

@rashkur
Last active December 19, 2019 10:47
Show Gist options
  • Save rashkur/2126aa205f8cf62aa3bad3bbeb5e4ad9 to your computer and use it in GitHub Desktop.
Save rashkur/2126aa205f8cf62aa3bad3bbeb5e4ad9 to your computer and use it in GitHub Desktop.
Autonomous system (ASN) lookup
#!/usr/bin/expect
#"AS61119,AS60863,AS51286,AS49988,AS49797,AS47764,AS21051,AS206494,AS47764":"mailru,odnoklassniki", "AS47541,AS47542,AS28709":"vkontakte", "AS43247,AS207207,AS202611,AS13238":"yandex"
set timeout 60
log_user 0
spawn telnet route-server.he.net
foreach as {61119 60863 51286 49988 49797 47764 21051 206494 47764 47541 47542 28709 43247 207207 202611 13238 1} {
expect {
"route-server> " {
log_user 1
send "show ip bgp regexp $as\r";
}
-ex "--More--" {send "\r"; exp_continue;}
}
}
send "exit\r"
# cat as.txt | sed 's/ --More--.*\*/\*/g' > as2.txt
# for net in $(cat as2.txt | grep -aoh -E '[0-9]+\.[0-9]+\.[0-9]+\.(0|[0-9]+\/[0-9]{1,2})' | sed 's/\.0\.0$/\.0\.0\/16/g') ; do echo -ne "route " ; ipcalc -n -b $net | awk '$1 ~ /Addres|Netmask/{printf $2" "}' ; echo; done
#in this example we exluding ip 88.198.23.171
ranges=(88.198.0.0-88.198.23.170 88.198.23.172-88.198.255.255)
for subnet in ${ranges[@]} ; do
ipcalc $subnet | while read line ; do ipcalc -b -c -n "$line" | awk '$1 ~ /Address|Netmask/{printf $2" "}' ; echo ; done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment