z_ip_address (zotonic_stdlib v1.34.0)
View SourceMisc utility URL functions for zotonic
Summary
Functions
Check if an IP address matches a list of addresses and masks like "127.0.0.0/8,10.0.0.0/8,fe80::/10"
Check for loopback, private-use, shared (CGNAT), or link-local addresses. IPv4: 127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 169.254.0.0/16, and 100.64.0.0/10. IPv6: ::1, fc00::/7, and fe80::/10. IPv4-mapped IPv6 addresses (::ffff:0:0/96) use the embedded IPv4 classification. This is not a public-address test: false also covers unspecified, multicast, documentation, benchmarking, and other reserved or special-purpose addresses.
Check if the host name resolves to a local IP address.
Conservative public-unicast address classification for outbound requests. Excludes local, unspecified, multicast, documentation, benchmarking, reserved, and special protocol/transition ranges. IPv6 is limited to 2000::/3, excluding 2001::/23, 2001:db8::/32, 2002::/16, and 3fff::/20. Special-purpose exceptions inside excluded ranges are deliberately not allowed, even if globally reachable. IPv4-mapped IPv6 addresses inherit the embedded IPv4 classification. This classifies address ranges; it does not prove reachability or trust.
Check whether every IPv4 and IPv6 address of a name is public. Literal addresses are classified directly. Names without addresses, invalid input, and resolver errors return false. An absent address family (nxdomain) is allowed when the other family has public addresses. This is a DNS snapshot, not protection against DNS rebinding between checking and connecting.
Functions
-spec ip_match(undefined | string() | binary() | tuple(), local | any | none | list() | string() | binary()) -> boolean().
Check if an IP address matches a list of addresses and masks like "127.0.0.0/8,10.0.0.0/8,fe80::/10"
-spec is_local(inet:ip_address()) -> boolean().
Check for loopback, private-use, shared (CGNAT), or link-local addresses. IPv4: 127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 169.254.0.0/16, and 100.64.0.0/10. IPv6: ::1, fc00::/7, and fe80::/10. IPv4-mapped IPv6 addresses (::ffff:0:0/96) use the embedded IPv4 classification. This is not a public-address test: false also covers unspecified, multicast, documentation, benchmarking, and other reserved or special-purpose addresses.
Check if the host name resolves to a local IP address.
-spec is_public(IP) -> boolean() when IP :: inet:ip_address().
Conservative public-unicast address classification for outbound requests. Excludes local, unspecified, multicast, documentation, benchmarking, reserved, and special protocol/transition ranges. IPv6 is limited to 2000::/3, excluding 2001::/23, 2001:db8::/32, 2002::/16, and 3fff::/20. Special-purpose exceptions inside excluded ranges are deliberately not allowed, even if globally reachable. IPv4-mapped IPv6 addresses inherit the embedded IPv4 classification. This classifies address ranges; it does not prove reachability or trust.
Check whether every IPv4 and IPv6 address of a name is public. Literal addresses are classified directly. Names without addresses, invalid input, and resolver errors return false. An absent address family (nxdomain) is allowed when the other family has public addresses. This is a DNS snapshot, not protection against DNS rebinding between checking and connecting.