Function isPublicNetworkAddress

  • Whether address, an IPv4 or IPv6 address as text, is on the public internet: not this machine, a private or link-local network, or a documentation, benchmarking, multicast, reserved or unallocated range, and for an IPv6 address that carries an IPv4 one (IPv4-mapped, NAT64, 6to4), not one whose IPv4 address is any of those. Brackets around an IPv6 address are allowed. Text that is not an IP address is not public, and neither is an IPv6 address with a zone (fe80::1%en0).

    Parameters

    Returns boolean

    Example

    isPublicNetworkAddress('8.8.8.8');            // true
    isPublicNetworkAddress('169.254.169.254'); // false: link-local, cloud metadata
    isPublicNetworkAddress('[::ffff:127.0.0.1]'); // false: loopback, IPv4-mapped
    isPublicNetworkAddress('4000::1'); // false: outside 2000::/3