Project

ipaddr

0.15
The project is in a healthy, maintained state
IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and IPv6 are supported.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies
 Project Readme

IPAddr

IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and IPv6 are supported.

Build Status

Installation

This library is part of the standard ruby distribution as default gem and synchronized periodically, but you can explicitly depend on this gem with version constraints as necessary, like when you need a newer version than comes with older versions of ruby.

For example, you can add this line to your application's Gemfile:

gem 'ipaddr', '~> 1.2'

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>

Alternative

The ipaddress gem is a popular, extensive library for manipulating IP addresses with a layer of compatibility with ipaddr. If you need a richer set of features than ipaddr has, try this library instead.

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.