io.randomseed.utils.ip

added in 1.0.0

Random utils, IP address support functions.

address

(address s)(address a b c d)(address a b c d e f g h i j k l m n o p)

Converts the given value to an IP address. Can work with strings, byte arrays, sequences of bytes and numbers. When 4 (for IPv4) or 16 (for IPv6) arguments are given, they should be a bytes or values which may be converted to (unchecked) bytes.

bytes-to-address

(bytes-to-address b)(bytes-to-address b & bytes)

Coverts a byte array to an IP address. If there are 4 bytes are less, an IPv4 address will be created, otherwise IPv6. When more than one argument is given, it will create a byte array, converting each argument’s value to an unchecked byte. Will throw an exception if a number given for a byte is lesser than 0 or greater than 255.

bytes-to-ipv4

(bytes-to-ipv4 b)(bytes-to-ipv4 a b c d)

Creates new IPv4 address using an array of bytes. When 4 arguments are given, they will be used to create a byte array. Will throw an exception if a number given for a byte is lesser than 0 or greater than 255.

bytes-to-ipv6

(bytes-to-ipv6 b)(bytes-to-ipv6 a b c d e f g h i j k l m n o p)

Creates new IPv6 address using an array of bytes. When 16 arguments are given, they will be used to create a byte array. Will throw an exception if a number given for a byte is lesser than 0 or greater than 255.

in4t?

(in4t? trie ip)

Returns true if an IPv6 address is contained within the given tree.

in6t?

(in6t? trie ip)

Returns true if an IPv6 address is contained within the given tree.

inet-address?

(inet-address? v)

Returns true if the given value is of a type java.net.InetAddress.

ip?

(ip? v)

Returns true if the given value (a string, a number, a sequence of bytes, or an IP address object) represents a valid IP address.

ipv4-mapped?

(ipv4-mapped? v)

Returns true if the given value (a string, a number, a sequence of bytes, or an IP address object) represents a valid IPv4 address and it is a IPv4-mapped IPv6 address.

ipv4?

(ipv4? v)

Returns true if the given value (a string, a number, a sequence of bytes, or an IP address object) represents a valid IPv4 address.

ipv6?

(ipv6? v)

Returns true if the given value (a string, a number, a sequence of bytes, or an IP address object) represents a valid IPv6 address.

is-ip?

(is-ip? v)

Returns true if the given value is of type inet.ipaddr.IPAddress.

is-ipv4-mapped?

(is-ipv4-mapped? v)

Returns true if the given value is of type inet.ipaddr.ipv6.IPv6Address and it is IPv4-mapped address.

is-ipv4?

(is-ipv4? v)

Returns true if the given value is of type inet.ipaddr.ipv4.IPv4Address.

is-ipv6?

(is-ipv6? v)

Returns true if the given value is of type inet.ipaddr.ipv6.IPv6Address.

java-inet-to-address

(java-inet-to-address v)

Converts java.net.InetAddress to IP address.

number-to-address

(number-to-address n)

Coverts a number to an IP address. If the number is a kind of java.math.BigInteger or clojure.lang.BigInt, the IPv6 address will be created. Otherwise the number will be converted to int and IPv4 address will be created.

number-to-ipv4

(number-to-ipv4 n)

Coverts a number to an IPv4 address.

number-to-ipv6

(number-to-ipv6 n)

Coverts a number to an IPv6 address.

plain-ip

(plain-ip ip)

Returns an IP address. If the address can be expressed as IPv4, it is returned as IPv4, otherwise as IPv6.

plain-ip-str

(plain-ip-str ip)

Returns string representation of IP address (if the address can be expressed as IPv4, it is returned as 4 octets in dotted-decimal notation, otherwise IPv6 representation is returned).

preprocess-ip-list

(preprocess-ip-list p)

Takes a sequence of IP addresses and returns a vector of Trie trees with IP address ranges.

string-to-address

(string-to-address s)

Coverts a string to an IP address.

to-address

(to-address s)(to-address a b c d)(to-address a b c d e f g h i j k l m n o p)

Converts the given value to an IP address. Can work with strings, byte arrays, sequences of bytes and numbers. When 4 (for IPv4) or 16 (for IPv6) arguments are given, they should be a bytes or values which may be converted to (unchecked) bytes.

to-str

(to-str ip)

Converts IP address to a string. Returns nil if it is not possible.

to-str-plain

(to-str-plain ip)

Returns string representation of IP address (if the address can be expressed as IPv4, it is returned as 4 octets in dotted-decimal notation, otherwise IPv6 representation is returned).

to-str-v4

(to-str-v4 ip)

Converts IP address to a string expressing IPv4 notation. Returns nil if this is not possible.

to-str-v6

(to-str-v6 ip)

Converts IP address to a string expressing IPv6 notation. Returns nil if this is not possible.

to-string

(to-string ip)

Converts IP address to a string. Returns nil if it is not possible.

to-string-v4

(to-string-v4 ip)

Converts IP address to a string expressing IPv4 notation. Returns nil if this is not possible.

to-string-v6

(to-string-v6 ip)

Converts IP address to a string expressing IPv6 notation. Returns nil if this is not possible.

to-v4

(to-v4 v)

Converts the given IP address to IPv4. Returns nil if this is not possible.

to-v6

(to-v6 v)

Converts the given IP address to IPv6. Returns nil if this is not possible.

ubyte

(ubyte v)

Converts to an unchecked byte used to express unsigned values. Throws an IllegalArgumentException exception if the given value is not a byte but exceeds the range of 0-255.