Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?
share|improve this question
What do you mean by calculate all IPs? You already have a list of IPs. Do you want to change to ... – terdon Sep 16 '12 at 12:04
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:



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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .