INNER CODE UNIT · Python

_is_special_ip

magicsword-io/LOLRMM · bin/lint_content.py:124

def _is_special_ip(value: str) -> tuple[bool, str | None]:
    """Return (True, reason) if value is an IP in a special-use range."""
    try:
        ip = ipaddress.ip_address(value)
    except ValueError:
        return False, None
    if ip.is_loopback:
        return True, "loopback IP"
    if ip.is_link_local:
        return True, "link-local IP"
    if ip.is_multicast:
        return True, "multicast IP"
    if ip.is_unspecified:
        return True, "unspecified IP (0.0.0.0 / ::)"
    if ip.is_private:
        return True, "RFC1918 / private IP"
    if isinstance(ip, ipaddress.IPv6Address) and ip.is_reserved:
        return True, "reserved IPv6 address"

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…