Get IP address Space By AS(Autonomous System) Number

Sometimes you need to get all possible address blocks of a network but most of the time there is no easy way to figure it out, looking at you Facebook and Google, but fear not sysadmin we have one handy trick up in our sleeve, by using whois with the AS number of the company we can build this kind of list.
We’ll use Facebook(AS32934) as an example, but it should work for any Autonomous System.

whois -h -- "-i origin AS32934" | grep ^route | tr -s " " | cut -d " " -f2-

The output should look like this:


And with this you have the full list of networks assigned to the AS, you can block/redirect/prioritize as you see fit, and as with most lists this is not a static one so you should build a script and update it from time to time.