Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
Dependencies
other
Versions
Useage
Deno
import * as netTools from "https://deno.land/x/cidr/mod.js"API
import { isCIDRv4, isIP, isIPv4, isIPv4InCIDR } from "https://deno.land/x/cidr/mod.js"
// isIP returns `number`. It will return `0` if params isn't v4 or v6
isIP('::1') // returns 6
isIP('127.0.0.1') // returns 4
isIP('127.000.000.001') // returns 0
isCIDRv4("192.168.50.1/16") // true
isCIDRv4("192.168.50.1") // false
isIPv4InCIDR('192.168.50.1/16', '192.168.50.12') // true
isIPv4InCIDR('192.168.50.16/24', '192.168.50.255', { isBroadcast: true }) // true
isIPv4InCIDR('192.168.50.16/24', '192.168.50.0', { isNetwork: true }) // trueYou can use isIPv4 if you only want to determine whether an IP is IPv4, it returns boolean.
isIPv4InCIDRis to determine whether an IP is within the CIDR range. The first parameter isCIDRrange, the second paramter isIPaddress.In the third paramters, you can choose
isNetworkorBroadcast, which is used to judge whether is a network/broadcast address. But it’s better not to write both. And CIDR’s rang is preferably 0 ~ 30 (includes 0 and 30)
Sure, you can use
CIDRv4IPif you need to iterate allIPin theCIDRrange. Like this:
const gen = CIDRv4IP("1.1.1.1/30")
gen.next().value //"1.1.1.0"
gen.next().value //"1.1.1.1"
gen.next().value //"1.1.1.2"
gen.next().value //"1.1.1.3"