IPAddr
IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and IPv6 are supported.
Installation
Add this line to your application's Gemfile:
gem 'ipaddr'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ipaddr
Usage
require 'ipaddr'
ipaddr1 = IPAddr.new "3ffe:505:2::1"
p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
p ipaddr1.to_s #=> "3ffe:505:2::1"
ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
p ipaddr2.to_s #=> "3ffe:505:2::"
ipaddr3 = IPAddr.new "192.168.2.0/24"
p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/ipaddr.
License
The gem is available as open source under the terms of the 2-Clause BSD License.