CIDR aggregator for IPv4 addresses
Add this line to your application's Gemfile:
gem 'cidr', :git => "https://github.com/izawa/cidr.git"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install cidr
require 'cidr'
aggregator = Cidr::Aggregator.new
aggregator.add('192.168.0.1')
aggregator.add('192.168.0.2')
aggregator.add('192.168.0.3')
aggregator.add('192.168.0.4')
aggregator.add('192.168.0.5')
aggregator.add('192.168.0.6')
aggregator.add('192.168.0.7')
aggregator.list
#=> [{:addr=>"192.168.0.1", :prefix=>32},
{:addr=>"192.168.0.2", :prefix=>31},
{:addr=>"192.168.0.4", :prefix=>30}]
aggregator.add will be able to recognize the input string in the following format.
- 192.168.0.1 (without prefix)
- 192.168.0.0/24 (with prefix)
'xxx.xxx.xxx.xxx' and 'xxx.xxx.xxx.xxx/32' are assumed to be identical.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request