module Subnet
Overview
TODO Write documentation for Subnet
Direct including types
Defined in:
subnet.crsubnet/ipv4.cr
subnet/ipv6.cr
subnet/prefix.cr
subnet/version.cr
Constant Summary
-
VERSION =
"0.1.0"
Constructors
- .new(value : JSON::PullParser) : Subnet
-
.parse(str) : Subnet
Parse the argument string to create a new IPv4, IPv6 or Mapped IP object
Class Method Summary
-
.deprecate(message = nil)
Deprecate method :nodoc:
-
.ntoa(uint)
Converts a unit32 to IPv4
-
.valid?(addr)
Checks if the given string is either a valid IP, either a valid IPv4 subnet
-
.valid_ip?(addr)
Checks if the given string is a valid IP address, either IPv4 or IPv6
-
.valid_ipv4?(addr)
Checks if the given string is a valid IPv4 address
-
.valid_ipv4_netmask?(addr)
Checks if the argument is a valid IPv4 netmask expressed in dotted decimal format.
-
.valid_ipv4_subnet?(addr)
Checks if the given string is a valid IPv4 subnet
-
.valid_ipv6?(addr)
Checks if the given string is a valid IPv6 address
-
.valid_ipv6_subnet?(addr)
Checks if the given string is a valid IPv6 subnet
Instance Method Summary
-
#ipv4?
True if the object is an IPv4 address
-
#ipv6?
True if the object is an IPv6 address
- #to_json(json : JSON::Builder)
Constructor Detail
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
Class Method Detail
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
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
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
Checks if the argument is a valid IPv4 netmask expressed in dotted decimal format.
Subnet.valid_ipv4_netmask? "255.255.0.0"
# => true
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
Checks if the given string is a valid IPv6 address
Example:
Subnet::valid_ipv6? "2002::1"
# => true
Subnet::valid_ipv6? "2002::DEAD::BEEF"
# => false
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
Instance Method Detail
True if the object is an IPv4 address
ip = Subnet.parse("192.168.10.100/24")
ip.ipv4?
# => true
True if the object is an IPv6 address
ip = Subnet.parse("192.168.10.100/24")
ip.ipv6?
# => false