Skip to content

How to get all ip prefixes announced by AS

If you need all ip prefixes announced by AS number for routing, filtering or info purposes, you can use whois client from Linux with args ‘-i origin -T route’

Example:

root@ns:~# whois AS9009 -i origin -T route |grep 'route:'
route:          128.0.1.0/24
route:          138.99.211.0/24
route:          172.111.129.0/24
route:          172.111.130.0/24
route:          172.111.138.0/24
route:          172.111.140.0/24
route:          172.111.141.0/24
route:          172.111.148.0/24
route:          172.111.178.0/24
..............

I use the default whois server: whois.ripe.net; You can bypass or change the whois server with ‘-h whois_server’.

For more filtered display:

root@ns:~# whois AS9009 -i origin -T route |grep 'route:' |grep 'route:' |awk '{print $2}'
128.0.1.0/24
138.99.211.0/24
172.111.129.0/24
172.111.130.0/24
172.111.138.0/24
172.111.140.0/24
....

Also, you can add as a bash function in ‘~/.bashrc’ or ‘~/.bash_profile’ file and use the command ‘routes

function routes() {
        whois $1 -i origin -T route|grep 'route:' | grep 'route:' |awk '{print $2}'
}

Example (after adding the function routes):

root@ns:~# routes AS9009
128.0.1.0/24
138.99.211.0/24
172.111.129.0/24
172.111.130.0/24
172.111.138.0/24
172.111.140.0/24
.......

More info:

Published inLinux