Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have this IP list shown below. How i can calculate all ip addresses from that in Linux? Is there some tools that can calculate that for me ? I need that to check if i have not banned some cloudflare IP's. As firewall i am using shorewall and i am banning with fail2ban single IP. As i know, then i cannot detect subent mask from IP adress, right?

204.93.240.0/24
204.93.177.0/24
199.27.128.0/21
173.245.48.0/20
103.22.200.0/22
141.101.64.0/18
108.162.192.0/18
190.93.240.0/20
188.114.96.0/20
share|improve this question
    
What do you mean by calculate all IPs? You already have a list of IPs. Do you want to change 11.22.33.0/5 to 11.22.33.0 11.22.33.1 ... 11.22.33.5? –  terdon Sep 16 '12 at 12:04

2 Answers 2

up vote 1 down vote accepted

I am not sure I have understood your question, but if you want to expand a list of IP ranges to all the IPs said ranges contain, try this:

$ perl -ne '/(.+)\.(\d+)\/(\d+)$/; print "$1.$_\n" foreach($2..$3)' iplist.txt > IPs

This will create a file called IPs containing:

204.93.240..0
204.93.240..1
204.93.240..2
204.93.240..3
 ...

188.114.96..18
188.114.96..19
188.114.96..20

You can then loop through the file and apply whatever tool you need (ping, for example) to each IP:

$ while read ip; do ping $ip; done < IPs

You can also combine the two commands if you do not want to create a file with all the IPs:

$ perl -ne '/(.+)\.(\d+)\/(\d+)$/; print "$1.$_\n" foreach($2..$3)' iplist.txt | while read ip; do ping $ip; done
share|improve this answer

No, ever since CIDR was introduced, you can't derive the netmask from the IP address. You can calculate the broadcast address (the highest address in the subnet) by converting the network address to an integer, add 2^(32-netmask), and convert the result back to quad-dotted decimal notation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.