Sometimes you need to know if a certain IP (or several ones) are within an IP range or belong to a certain ASN. Let’s give it a try and generate all possible IP addresses for

$ dig 
...     86346   IN  A

Now let’s find out the ASN:

$ whois | grep origin            
origin:         AS34086

Now ask RIPE for the IP ranges:

$ whois -h -T route AS34086 -i origin | egrep "route: " | awk '{print $NF}'

Now for every IP range let’s generate all possible IP addresses. Therefore I’ve wrote a simple python script.

I know there is cidr2range but that didn’t work for certain blocks like

$ cat 
#!/usr/bin/env python2

import sys
from netaddr import IPNetwork

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "Usage: %s <CIDR Block>\n" % sys.argv[0]
        for ip in IPNetwork(sys.argv[1]):
            print '%s' % ip

Now let’s generate the lists:

$ whois -h -T route AS34086 -i origin | egrep "route: " | awk '{print $NF}'  >> /tmp/ip-ranges.txt
$ cat /tmp/ip-ranges.txt | xargs -n1 ./ > /tmp/ip-lists.txt
$  head -n 10 /tmp/ip-lists.txt
$ wc -l /tmp/ip-lists.txt 
81920 /tmp/ip-lists.txt

Voila! :)