Type:
Class
Constants:
IN4MASK : 0xffffffff

32 bit mask for IPv4

IN6MASK : 0xffffffffffffffffffffffffffffffff

128 bit mask for IPv4

IN6FORMAT : (["%.4x"] * 8).join(':')

Format string for IPv6

RE_IPV4ADDRLIKE : %r{ \A (\d+) \. (\d+) \. (\d+) \. (\d+) \z }x

Regexp internally used for parsing IPv4 address.

RE_IPV6ADDRLIKE_FULL : %r{ \A (?: (?: [\da-f]{1,4} : ){7} [\da-f]{1,4} | ( (?: [\da-f]{1,4} : ){6} ) (\d+) \. (\d+) \. (\d+) \. (\d+) ) \z }xi

Regexp internally used for parsing IPv6 address.

RE_IPV6ADDRLIKE_COMPRESSED : %r{ \A ( (?: (?: [\da-f]{1,4} : )* [\da-f]{1,4} )? ) :: ( (?: ( (?: [\da-f]{1,4} : )* ) (?: [\da-f]{1,4} | (\d+) \. (\d+) \. (\d+) \. (\d+) ) )? ) \z }xi

Regexp internally used for parsing IPv6 address.

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

Example

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>
to_i

to_i() Instance Public methods Returns the integer representation of the ipaddr

2015-04-13 18:27:03
ip6_arpa

ip6_arpa() Instance Public methods Returns a string for DNS reverse lookup compatible

2015-04-13 17:35:08
ipv4_mapped?

ipv4_mapped?() Instance Public methods Returns true if the ipaddr is an IPv4-mapped

2015-04-13 18:02:13
&

&(other) Instance Public methods Returns a new ipaddr built by bitwise AND

2015-04-13 16:51:46
ipv6?

ipv6?() Instance Public methods Returns true if the ipaddr is an IPv6 address

2015-04-13 18:05:34
===

===(other) Instance Public methods Alias for:

2015-04-13 17:08:39
new

new(addr = '::', family = Socket::AF_UNSPEC) Class Public methods Creates a

2015-04-13 16:45:16
ntop

ntop(addr) Class Public methods Convert a network byte ordered string form of

2015-04-13 16:50:15
<=>

<=>(other) Instance Public methods Compares the ipaddr with another.

2015-04-13 17:01:24
new_ntoh

new_ntoh(addr) Class Public methods Creates a new ipaddr containing the given

2015-04-13 16:46:54