IP calculation with RUBY
Switch branches/tags
Nothing to show
Clone or download
Latest commit 63c563e May 6, 2012


Table of Contents

General description

This gem contains classes that make IP manipulation easier.

  • Works with IPV4 and IPV6.
  • Arithmetic operations (+, -, +=, -=). For example, if IP="", then IP+1="".
  • Bitwise operations between IPs (|, &, ^).
  • Left and righ shifts (<<, >>).
  • Print IP in various formats:
    • The standard dotted notation. For example:
    • Decimal value. For example: 3232238602
    • Binary. For example: 11000000101010000000110000001010
    • Hexadecimal. For example: c0a80c0a
    • Pretty binary. For example: 11000000.10101000.00001100.00001010
    • Pretty hexadecimal. For example: c0.a8.0c.0a
  • Subnet discovery. What is the "/23" subnet that contains this IP?
  • Subnet testing. Is this IP included in this subnet?
  • IP comparaison (>, <, >=, <=, ==, !=, <=>). For example: "" > "" : FALSE
  • Manipulate IP like array. For examples, if IP="":
    • IP[1] is 20.
    • IP[1] = 55, then IP=""
  • Create IPs from integers of strings.


Ruby 1.9.1 or greater (tested with Ruby 1.9.3)

Building the gem from sources

gem build ipcalc.gemspec

Installing the gem

Installing from rubygems.org

If you just want to use the gem, then this is the preferred installation procedure.

gem list -r ipcalc

gem install ipcalc

Installing from local file system

This procedure assumes that you have downloaded the gem' sources from GutHub. If you just need to use the gem, you should install the gem from "Rubygems.org" (see next section).

You need to build the gem.

gem build ipcalc.gemspec

Then you can install the gem. Please note that we assume that the gem's version is 1.0.0.

gem install ipcalc-1.0.0.gem


See the example file: https://github.com/denis-beurive/ipcalc/tree/master/examples

Building the documentation

Using Rdoc:

rdoc lib/ipcalc/*.rb

Or, you can call rake:

rake rdoc


Denis BEURIVE (http://beurive.com/)