This is a only version

Found at: raymii.org:70/Get_all_IP_ranges_from_an_AS_number.txt

This is a text-only version of the following page on https://raymii.org:
Title       : 	Get all IP ranges from an AS number
Author      : 	Remy van Elst
Date        : 	04-01-2015
URL         : 	https://raymii.org/s/snippets/Get_all_IP_ranges_from_an_AS_number.html
Format      : 	Markdown/HTML

One of my clients wanted to block a few social networking websites. Since they
have no IPv6 (yet) I figured the simplest way was to block access to the entire
IP range. This won't work for all the CDN networks they use, but it does get you

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.

To find all the ranges beloning to an AS number you can query the
`whois.radb.net` server with the AS number.

For Facebook for example:

    whois -h whois.radb.net '!gAS32934'
    A1063 69

For CloudVPS:

    whois -h whois.radb.net '!gAS35470'

To find an AS number, you can query this whois server with the IP address.
Linode for example:

    $ whois -h whois.radb.net
    descr:          Linode-2
    origin:         AS15830
    mnt-by:         Linode-mnt
    changed:        tasaro@linode.com 20100510
    source:         RIPE
    remarks:        ****************************
    remarks:        * THIS OBJECT IS NOT VALID
    remarks:        * Please note that all personal data has been removed from this object.
    remarks:        * To view the original object, please query the RIPE Database at:
    remarks:        * http://www.ripe.net/whois
    remarks:        ****************************

And then their AS number:

    $ whois -h whois.radb.net '!gAS15830'
    A3937 [...]

A block can then be issued with the following `iptables` command:

    iptables -A INPUT -d -j DROP

Where `-d` is the destination you want to make unreachable.

If you have the `ipset` extension enabled you can create a set of all the

    ipset -N blocked_nets nethash
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets
    ipset -A blocked_nets

And create the rules to filter based on the `ipset`, which is faster when you
have a large amount of IP's and ranges.

    iptables -I INPUT -m set --match-set blocked_nets src,dst -j DROP

   [1]: https://www.digitalocean.com/?refcode=7435ae6b8212


All the text on this website is free as in freedom unless stated otherwise. 
This means you can use it in any way you want, you can copy it, change it 
the way you like and republish it, as long as you release the (modified) 
content under the same license to give others the same freedoms you've got 
and place my name and a link to this site with the article as source.

This site uses Google Analytics for statistics and Google Adwords for 
advertisements. You are tracked and Google knows everything about you. 
Use an adblocker like ublock-origin if you don't want it.

All the code on this website is licensed under the GNU GPL v3 license 
unless already licensed under a license which does not allows this form 
of licensing or if another license is stated on that page / in that software:

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .

Just to be clear, the information on this website is for meant for educational 
purposes and you use it at your own risk. I do not take responsibility if you 
screw something up. Use common sense, do not 'rm -rf /' as root for example. 
If you have any questions then do not hesitate to contact me.

See https://raymii.org/s/static/About.html for details.