module

Subnet

TODO: Write documentation for Subnet

Constants

VERSION = "0.1.0"

Constructors

parse(str) : Subnet

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

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

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

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

Class methods

deprecate(message = nil)

Deprecate method :nodoc:

Source
ntoa(uint)

Converts a unit32 to IPv4

Subnet::ntoa(167837953)
  # => "10.1.1.1"
Source
valid?(addr)

Checks if the given string is either a valid IP, either a valid IPv4 subnet

Example:

Subnet::valid? "10.0.0.0/24"
  # => true

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

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

Subnet::valid? "10.0.0.0/999"
  # => false
Source
valid_ip?(addr)

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

Example:

Subnet::valid_ip? "2002::1"
  # => true

Subnet::valid_ip? "10.0.0.256"
  # => false
Source
valid_ipv4?(addr)

Checks if the given string is a valid IPv4 address

Example:

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

Subnet::valid_ipv4? "172.16.10.1"
  # => true
Source
valid_ipv4_netmask?(addr)

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

Subnet.valid_ipv4_netmask? "255.255.0.0"
# => true
Source
valid_ipv4_subnet?(addr)

Checks if the given string is a valid IPv4 subnet

Example:

Subnet::valid_ipv4_subnet? "10.0.0.0/24"
  # => true

Subnet::valid_ipv4_subnet? "10.0.0.0/255.255.255.0"
  # => true

Subnet::valid_ipv4_subnet? "10.0.0.0/64"
  # => false
Source
valid_ipv6?(addr)

Checks if the given string is a valid IPv6 address

Example:

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

Subnet::valid_ipv6? "2002::DEAD::BEEF"
  # => false
Source
valid_ipv6_subnet?(addr)

Checks if the given string is a valid IPv6 subnet

Example:

Subnet::valid_ipv6_subnet? "::/0"
  # => true

Subnet::valid_ipv6_subnet? "dead:beef:cafe:babe::/64"
  # => true

Subnet::valid_ipv6_subnet? "2001::1/129"
  # => false
Source

Instance methods

ipv4?

True if the object is an IPv4 address

ip = Subnet.parse("192.168.10.100/24")

ip.ipv4?
# => true
Source
ipv6?

True if the object is an IPv6 address

ip = Subnet.parse("192.168.10.100/24")

ip.ipv6?
# => false
Source
to_json(json : JSON::Builder)
Source

Nested types