Static
abbreviateAbbreviate an IP-representing string. For example:
192.168.0.1
(for IPv4 addresses, same as IPUtil.sanitize)fd12:3456:789a:1::
Note that inaccurate CIDRs will be corrected:
fd12:3456:789a:1:0:0:0:1/64
fd12:3456:789a:1::/64
Optional
capitalize: booleanWhether to capitalize the output, which defaults to false
.
Optional
conditionPredicate: ConditionPredicateOptional IP address conditions to perform stringification.
null
if:
conditionPredicate
Protected
Static
checkProtected
Check the equality of two IP addresses.
An object of arrays of the IP parts in decimals.
An IP- or CIDR-representing string, or an IP instance.
null
if ipStr
does not represent an IP address.
Static
cleanReturn a trimmed string from which all occurrences of unicode bidi characters are removed.
"Unicode bidi characters" are special characters shown as red dots in WikiEditor, which can slip into cut-and-pasted strings. When we evaluate whether a string represents an IP address, these can cause serious trouble.
Protected
Static
compareProtected
Compare two ranges to check their inclusion relationship.
An object of arrays of the IP parts in decimals.
Which of ip1
and ip2
is expected to be broader.
null
if ip2
does not represent an IP address.
Static
containsStatic
containsStatic
containsEvaluate whether the IP address associated with cidrStr
contains any IP address
in the ipArr
array.
The index number of the first match in the ipArr
array, or -1
if there is
no match. null
will be returned if cidrStr
does not represent an IP address.
Static
equalsStatic
equalsStatic
equalsEvaluate whether the IP address associated with ipStr
equals any IP address
in the ipArr
array.
The index number of the first match in the ipArr
array, or -1
if there is
no match. null
will be returned if ipStr
does not represent an IP address.
Protected
Static
getProtected
Given an IP string or instance, parse it into an object of arrays of decimals that represent the parts of the first and last IPs.
null
if the input string does not represent an IP address.
Static
isCIDREvaluate whether a string represents a CIDR.
Evaluate whether a string represents a CIDR, with the strict CIDR validation mode on.
Optional
options: StringifyOptionsOptional specifications of how the output CIDR string should be formatted.
Static
isIPEvaluate whether a string represents an IP address.
Optional
allowCidr: booleanWhether to allow CIDRs, which defaults to false
.
Evaluate whether a string represents an IP address, with the strict CIDR validation mode on.
Optional
options: StringifyOptionsOptional specifications of how the output CIDR string should be formatted.
Static
isIPv4Evaluate whether a string represents an IPv4 address.
Optional
allowCidr: booleanWhether to allow CIDRs, which defaults to false
.
Evaluate whether a string represents an IPv4 address, with the strict CIDR validation mode on.
Optional
options: StringifyOptionsOptional specifications of how the output CIDR string should be formatted.
Static
isIPv4CIDREvaluate whether a string represents an IPv4 CIDR.
Evaluate whether a string represents an IPv4 CIDR, with the strict CIDR validation mode on.
Optional
options: StringifyOptionsOptional specifications of how the output CIDR string should be formatted.
Static
isIPv6Evaluate whether a string represents an IPv6 address.
Optional
allowCidr: booleanWhether to allow CIDRs, which defaults to false
.
Evaluate whether a string represents an IPv6 address, with the strict CIDR validation mode on.
Optional
options: StringifyOptionsOptional specifications of how the output CIDR string should be formatted.
Static
isIPv6CIDREvaluate whether a string represents an IPv6 CIDR.
Evaluate whether a string represents an IPv6 CIDR, with the strict CIDR validation mode on.
Optional
options: StringifyOptionsOptional specifications of how the output CIDR string should be formatted.
Static
isStatic
isEvaluate whether the IP address associated with ipStr
is within any IP range
in the cidrArr
array.
The index number of the first match in the cidrArr
array, or -1
if there is
no match. null
will be returned if ipStr
does not represent an IP address.
Static
isStatic
lengthenLengthen an IP-representing string. For example:
192.168.000.001
fd12:3456:789a:0001:0000:0000:0000:0000
Note that inaccurate CIDRs will be corrected:
fd12:3456:789a:1:0:0:0:1/64
fd12:3456:789a:0001:0000:0000:0000:0000/64
Optional
capitalize: booleanWhether to capitalize the output, which defaults to false
.
Optional
conditionPredicate: ConditionPredicateOptional IP address conditions to perform stringification.
null
if:
conditionPredicate
Protected
Static
modProtected
Static
parseProtected
Parse a string that potentially represents an IP or CIDR address.
Optional
bitLen: numberAn optional bit length of the IP address.
A parsed object, or null
if:
ipStr
is not a string.ipStr
does not represent an IP address.ipStr
contains an invalid bit length for a CIDR.Protected
Static
parseProtected
Parse an IP string into an array and convert back into a string.
Optional
conditionPredicate: ConditionPredicateOptional IP address conditions to perform stringification.
null
if:
conditionPredicate
Protected
Static
parseProtected
Get the start and end IP addresses for the range of bitLen
as an object of arrays of decimals.
Static
sanitizeSanitize an IP-representing string. For example:
192.168.0.1
(for IPv4 addresses, same as IPUtil.abbreviate)fd12:3456:789a:1:0:0:0:0
Note that inaccurate CIDRs will be corrected:
fd12:3456:789a:1::1/64
fd12:3456:789a:1:0:0:0:0/64
Optional
capitalize: booleanWhether to capitalize the output, which defaults to false
.
Optional
conditionPredicate: ConditionPredicateOptional IP address conditions to perform stringification.
null
if:
conditionPredicate
Protected
Static
stringifyProtected
Stringify an array of IP parts in decimals.
Optional
options: StringifyOptions = {}Private
Static
validateValidate a string as an IP address under certain conditions.
Optional
conditionPredicate: ConditionPredicateValidate a string as an IP address under certain conditions.
Optional
conditionPredicate: ConditionPredicateOptional
options: StringifyOptions
The IPUtil class. Unlike the IP class, this class provides several static methods that can be used to perform validations on an IP or CIDR address just once, or on varying IP or CIDR addresses.