• Check if a Subnet is valid

    Parameters

    • ip: string
    • type: "v4" | "v6" | "v6 | v4" = 'v6 | v4'

    Returns "v4" | "v6" | false

    Subnet IP Type or false if failed

    Example

    import { network } from "@rjweb/utils"

    network.isSubnet('127.0.0.1', 'v4') // false
    network.isSubnet('127.0.0.1', 'v6') // false
    network.isSubnet('::1/128', 'v6') // 'v6'
    network.isSubnet('127.0.0.1/32', 'v6 | v4') // 'v4'
    network.isSubnet('1.1') // false
    network.isSubnet('1.1/32') // 'v4'

    Since

    1.7.0

    Supports

    nodejs, browser