Module talk:IP/doc 20230319

Util

The  class provides (static) utility methods to work with single IP addresses and subnetworks.

removeDirMarkers

Removes,  , and   from a given string and returns a new string. For instance, the  is a special character represented by a red dot in the wikitext editor. Template parameters can occasionally involve these special characters, and methods in this module throw an error if a string involving such characters is passed to them. prevents this issue. The methods in the  class, listed below, all call this method internally at the very first step of their procedures.

isIPAddress

Returns  if a given string is a valid IP address, or   if not. If a CIDR string should be allowed, pass  to , and if a CIDR string should only be allowed, pass   to. (Note that the value of  is ignored if   is  .)

Examples:

In more detail,  returns 3 values: ,  ,.

is the result of whether the input string is a valid IP address or CIDR,  is the input string, and   is a corrected CIDR string or. In the fourth example above, "1.2.3.0/24" is a CIDR for "1.2.3.0 - 1.2.3.255"; hence "1.2.3.4/24" is an inappropriate subnet and evaluated as a non-CIDR (for this reason  throws an error). Beware that  attempts to correct an inappropriate subnet to an appropriate one and then evaluates whether the input string is a CIDR, if either   or   is. is always  if   is , and can have a string value only if   is. It is also important that if  has a value, the input string in itself is not a valid CIDR.

isIPv4Address

Returns  if a given string is a valid IPv4 address, or   if not. If a CIDR string should be allowed, pass  to , and if a CIDR string should only be allowed, pass   to. (Note that the value of  is ignored if   is  .) As well as ,   returns 3 values.

isIPv6Address

Returns  if a given string is a valid IPv6 address, or   if not. If a CIDR string should be allowed, pass  to , and if a CIDR string should only be allowed, pass   to. (Note that the value of  is ignored if   is  .) As well as ,   returns 3 values.