class IPAddress::IPv6

Overview

Class IPAddress::IPv6 is used to handle IPv6 type addresses.

IPv6 addresses

IPv6 addresses are 128 bits long, in contrast with IPv4 addresses which are only 32 bits long. An IPv6 address is generally written as eight groups of four hexadecimal digits, each group representing 16 bits or two octect. For example, the following is a valid IPv6 address:

2001:0db8:0000:0000:0008:0800:200c:417a

Letters in an IPv6 address are usually written downcase, as per RFC. You can create a new IPv6 object using uppercase letters, but they will be converted.

Compression

Since IPv6 addresses are very long to write, there are some semplifications and compressions that you can use to shorten them.

Using compression, the IPv6 address written above can be shorten into the following, equivalent, address:

2001:db8::8:800:200c:417a

This short version is often used in human representation.

Network Mask

As we used to do with IPv4 addresses, an IPv6 address can be written using the prefix notation to specify the subnet mask:

2001:db8::8:800:200c:417a/64

The /64 part means that the first 64 bits of the address are representing the network portion, and the last 64 bits are the host portion.

Included Modules

Defined in:

lib/ipaddress/src/ipaddress/ipv6.cr
coffee/extra/ipaddress/ipv6.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.parse_u128_address(u128 : BigInt, prefix = 128) : IPAddress #

[View source]

Instance Method Detail

def each(&) : Nil #

Iterates over all the IP addresses for the given network (or IP address).

The object yielded is a new IPv6 object created from the iteration.

ip6 = IPAddress.new "2001:db8::4/125"

ip6.each do |i|
  p i.compressed
end
# => "2001:db8::"
# => "2001:db8::1"
# => "2001:db8::2"
# => "2001:db8::3"
# => "2001:db8::4"
# => "2001:db8::5"
# => "2001:db8::6"
# => "2001:db8::7"

NOTE If the host portion is very large, this method can be very slow and possibly hang your system!


[View source]
def includes?(other : IPv4) #

[View source]
def includes?(others : Array(IPv4)) #

[View source]
def includes?(*others : IPv4) #

[View source]