libnrdpd.util¶
Supporting utility functions for the librndpd library.
-
class
libnrdpd.util.
IP
(ipv4, ipv6)[source]¶ Bases:
object
Class defining the IP address for a host.
- Params:
ipv4 (str or None): IPv4 address ipv6 (str or None): IPv6 address
-
property
address
¶ Default IP address for the host.
The preference is for IPv6, so if both an IPv6 and IPv4 address are defined on the host, it will use the IPv6 address.
-
property
v4
¶ IPv4 address if present.
If no IPv4 address is defined for the host this will return 127.0.0.1. This is to make sure configs at least have something to report when someone forces {ip.v4}.
-
property
v6
¶ IPv6 address if present.
If no IPv6 address is defined for the host this will return ::1. This is to make sure configs at least have something to report when someone forces {ip.v6}.
-
libnrdpd.util.
getip
()[source]¶ Determine the IP of the machine.
- Returns
IP
Representing the IP address of the box
- Raises
libnrdpd.error.NrdpdError – When no IP is able to be determined.
-
libnrdpd.util.
min_float_val
(value, minval, name)[source]¶ Convert argument to float assuring it meets it’s minimal value.
- Params:
value: Incoming value to convert and validate. minval: Minimal value for the float. name: Used in exceptions to identify the bad variable.
- Raises
libnrdpd.error.ConfigError – Raised on invalid numbers. The
.err
property is set toTYPE_ERROR
when conversion to float fails. It is set toVALUE_ERROR
when the value doesn’t meet theminval
minimum value.
-
libnrdpd.util.
IPV4_ADDRS
= ['1.1.1.1', '8.8.8.8', '74.6.231.2', '23.53.34.25', '23.10.60.33', '144.160.155.43']¶ Test addresses for determining host’s IPv4 address.
No traffic is sent, just a UDP socket is created so we can determine what the OS thinks is a good default route IP address. Many IPs are tested to acquire a statistical model of the most likely default route.
-
libnrdpd.util.
IPV6_ADDRS
= ['2620:119:35::35', '2001:4860:4860::8888', '2001:4998:44:3507::8001', '2600:1409:3800::ace8:c60', '2600:1406:1a:38d::2add', '2001:1890:1c00:3113::f:3005']¶ Test addresses for determining host’s IPv6 address.
No traffic is sent, just a UDP socket is created so we can determine what the OS thinks is a good default route IP address. Many IPs are tested to acquire a statistical model of the most likely default route.