Module IPAddress
In: lib/ipaddress.rb
lib/ipaddress/ipv6.rb
lib/ipaddress/prefix.rb
lib/ipaddress/ipv4.rb

Methods

Classes and Modules

Class IPAddress::IPv4
Class IPAddress::IPv6
Class IPAddress::Prefix
Class IPAddress::Prefix128
Class IPAddress::Prefix32

Constants

NAME = "IPAddress"
GEM = "ipaddress"
AUTHORS = ["Marco Ceresa <ceresa@ieee.org>"]

Public Class methods

Parse the argument string to create a new IPv4, IPv6 or Mapped IP object

  ip  = IPAddress.parse "172.16.10.1/24"
  ip6 = IPAddress.parse "2001:db8::8:800:200c:417a/64"
  ip_mapped = IPAddress.parse "::ffff:172.16.10.1/128"

All the object created will be instances of the correct class:

 ip.class
   #=> IPAddress::IPv4
 ip6.class
   #=> IPAddress::IPv6
 ip_mapped.class
   #=> IPAddress::IPv6::Mapped

Checks if the given string is a valid IP address, either IPv4 or IPv6

Example:

  IPAddress::valid? "2002::1"
    #=> true

  IPAddress::valid? "10.0.0.256"
    #=> false

Checks if the given string is a valid IPv4 address

Example:

  IPAddress::valid_ipv4? "2002::1"
    #=> false

  IPAddress::valid_ipv4? "172.16.10.1"
    #=> true

Checks if the argument is a valid IPv4 netmask expressed in dotted decimal format.

  IPAddress.valid_ipv4_netmask? "255.255.0.0"
    #=> true

Checks if the given string is a valid IPv6 address

Example:

  IPAddress::valid_ipv6? "2002::1"
    #=> true

  IPAddress::valid_ipv6? "2002::DEAD::BEEF"
    #=> false

Public Instance methods

True if the object is an IPv4 address

  ip = IPAddress("192.168.10.100/24")

  ip.ipv4?
    #-> true

True if the object is an IPv6 address

  ip = IPAddress("192.168.10.100/24")

  ip.ipv6?
    #-> false

[Validate]