Class
Constants
32 bit mask for IPv4
Format string for IPv6
128 bit mask for IPv6
Regexp internally used for parsing IPv4 address.
Regexp internally used for parsing IPv6 address.
Regexp internally used for parsing IPv6 address.
The version string
Attributes
Returns the address family of this IP address.
Class Methods
Creates a new ipaddr object either from a human readable IP address representation in string, or from a packed in_addr value followed by an address family.
In the former case, the following are the valid formats that will be recognized: “address”, “address/prefixlen” and “address/mask”, where IPv6 address may be enclosed in square brackets (‘[’ and ‘]’). If a prefixlen or a mask is specified, it returns a masked IP address. Although the address family is determined automatically from a specified string, you can specify one explicitly by the optional second argument.
Otherwise an IP address is generated from a packed in_addr value and an address family.
The IPAddr class defines many methods and operators, and some of those, such as &, |, include? and ==, accept a string, or a packed in_addr value instead of an IPAddr object.
Creates a new ipaddr containing the given network byte ordered string form of an IP address.
Convert a network byte ordered string form of an IP address into human readable form. It expects the string to be encoded in Encoding::ASCII_8BIT (BINARY).
Instance Methods
Returns a new ipaddr built by bitwise negation.
Returns a new ipaddr built by bitwise left shift.
Compares the ipaddr with another.
Returns true if two ipaddrs are equal.
Returns a new ipaddr built by bitwise right-shift.
Returns a new ipaddr built by bitwise OR.
Returns a new ipaddr less than the original address by offset
Returns a new ipaddr built by bitwise AND.
Returns a new ipaddr greater than the original address by offset
Returns a string containing the IP address representation with prefix.
Returns a string containing the IP address representation in cidr notation
Checks equality used by Hash.
Returns a network byte ordered string form of the IP address.
Returns true if the given ipaddr is in the range.
e.g.:
require 'ipaddr' net1 = IPAddr.new("192.168.2.0/24") net2 = IPAddr.new("192.168.2.100") net3 = IPAddr.new("192.168.3.0") net4 = IPAddr.new("192.168.2.0/16") p net1.include?(net2) p net1.include?(net3) p net1.include?(net4) p net4.include?(net1)
Returns a string containing a human-readable representation of the ipaddr. (“#<IPAddr: family:address/mask>”)
Returns a string for DNS reverse lookup compatible with RFC3172.
Returns a string for DNS reverse lookup compatible with RFC1886.
Returns true if the ipaddr is an IPv4 address.
Returns a new ipaddr built by converting the native IPv4 address into an IPv4-compatible IPv6 address.
Returns true if the ipaddr is an IPv4-compatible IPv6 address.
Returns a new ipaddr built by converting the native IPv4 address into an IPv4-mapped IPv6 address.
Returns true if the ipaddr is an IPv4-mapped IPv6 address.
Returns true if the ipaddr is an IPv6 address.
Returns true if the ipaddr is a link-local address. IPv4 addresses in 169.254.0.0/16 reserved by RFC 3927 and link-local IPv6 Unicast Addresses in fe80::/10 reserved by RFC 4291 are considered link-local. Link-local IPv4 addresses in the IPv4-mapped IPv6 address range are also considered link-local.
Returns true if the ipaddr is a loopback address. Loopback IPv4 addresses in the IPv4-mapped IPv6 address range are also considered as loopback addresses.
Returns a new ipaddr built by masking IP address with the given prefixlen/netmask. (e.g. 8, 64, “255.255.255.0”, etc.)
Set current netmask to given mask.
Returns a new ipaddr built by converting the IPv6 address into a native IPv4 address. If the IP address is not an IPv4-mapped or IPv4-compatible IPv6 address, returns self.
Returns the netmask in string format e.g. 255.255.0.0
Returns the prefix length in bits for the ipaddr.
Sets the prefix length in bits
Returns true if the ipaddr is a private address. IPv4 addresses in 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 as defined in RFC 1918 and IPv6 Unique Local Addresses in fc00::/7 as defined in RFC 4193 are considered private. Private IPv4 addresses in the IPv4-mapped IPv6 address range are also considered private.
Returns a string for DNS reverse lookup. It returns a string in RFC3172 form for an IPv6 address.
Returns the successor to the ipaddr.
Returns the integer representation of the ipaddr.
Returns a json string containing the IP address representation.
Creates a Range object for the network address.
Returns a string containing the IP address representation.
Returns a string containing the IP address representation in canonical form.
Returns the wildcard mask in string format e.g. 0.0.255.255
Returns the IPv6 zone identifier, if present. Raises InvalidAddressError if not an IPv6 address.
Returns the IPv6 zone identifier, if present. Raises InvalidAddressError if not an IPv6 address.