How to use the cidrSubnet function from ip

Find comprehensive JavaScript ip.cidrSubnet code examples handpicked from public code repositorys.

4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
mergedSecondaryInterface.ipOnly = ipAddress;
mergedSecondaryInterface.ipsubnet = ipSubnet.networkAddress + "/" + ipSubnet.subnetMaskLength;
mergedSecondaryInterface.ipnet = ipAddress.substring(0, ipAddress.lastIndexOf("."));
mergedSecondaryInterface.ipmask = subnetMask;
if (mergedSecondaryInterface.ip2) {
  const ipSubnet2 = iptool.cidrSubnet(mergedSecondaryInterface.ip2);
  mergedSecondaryInterface.ip2Only = mergedSecondaryInterface.ip2.substring(0, mergedSecondaryInterface.ip2.lastIndexOf('/')); // e.g., 192.168.168.1
  mergedSecondaryInterface.ipsubnet2 = ipSubnet2.networkAddress + "/" + ipSubnet2.subnetMaskLength; // e.g., 192.168.168.0/24
  mergedSecondaryInterface.ipnet2 = mergedSecondaryInterface.ip2.substring(0, mergedSecondaryInterface.ip2.lastIndexOf(".")); // e.g., 192.168.168
  mergedSecondaryInterface.ipmask2 = ipSubnet2.subnetMask; // e.g., 255.255.255.0
fork icon117
star icon463
watch icon0

+ 15 other calls in file

2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
    matchedRules.push(rule);
  }
} else if (['block_ip_set', 'sec_block_ip_set'].includes(ipsetName) && iptool.isV4Format(currentTxt)) {
  matchedRules = rules.filter(rule => rule.type == "ip" && rule.target === currentTxt);
} else if (['block_net_set', 'sec_block_net_set'].includes(ipsetName) && iptool.isV4Format(currentTxt)) {
  matchedRules = rules.filter(rule => rule.type == "net" && iptool.cidrSubnet(rule.target).contains(currentTxt));
} else if (['block_domain_set', 'sec_block_domain_set'].includes(ipsetName) && iptool.isV4Format(currentTxt)) {
  const filterRules = rules.filter(rule => ["dns", "domain"].includes(rule.type));
  if (isDomain) {
    const domains = await dnsTool.getAllDns(currentTxt); // 54.169.195.247 => ["api.github.com", "github.com"]
fork icon117
star icon463
watch icon0

+ 5 other calls in file

707
708
709
710
711
712
713
714
715
716
// only check conflict of IPv4 addresses here
if (!ipTool.isV4Format(ipAddr))
  continue;
if (isNaN(maskLength) || !Number.isInteger(Number(maskLength)) || Number(maskLength) > 32 || Number(maskLength) < 0)
  throw new Error(`${serverSubnet} is not a valid CIDR subnet`);
const serverSubnetCidr = ipTool.cidrSubnet(serverSubnet);
for (const iface of sysManager.getLogicInterfaces()) {
  const mySubnetCidr = iface.subnet && ipTool.cidrSubnet(iface.subnet);
  if (!mySubnetCidr)
    continue;
fork icon117
star icon463
watch icon0

+ 19 other calls in file

769
770
771
772
773
774
775
776
777
778
      return mask.substr(5);
    else
      return mask;
  } else {
    // parse subnet when netmask does not exist
    return iptool.cidrSubnet(intfObj.subnet).subnetMask
  }
} else {
  return undefined;
}
fork icon117
star icon463
watch icon0

+ 3 other calls in file

127
128
129
130
131
132
133
134
135
136
    (ip_module.isV6Format(address) && 'IPv6') ||
    '';
if (!family) return;
for (const [ifc, arr] of Object.entries(os.networkInterfaces())) {
    for (const info of arr) {
        if (info.family === family && ip_module.cidrSubnet(info.cidr).contains(address)) {
            return { ifc, info };
        }
    }
}
fork icon70
star icon229
watch icon17

378
379
380
381
382
383
384
385
386
387
for (const { kind, addr } of no_proxy_list) {
    if (isIp) {
        if (kind === 'IP' && ip.isEqual(addr, hostname)) {
            return false;
        }
        if (kind === 'CIDR' && ip.cidrSubnet(addr).contains(hostname)) {
            return false;
        }

    } else {
fork icon68
star icon227
watch icon0

+ 2 other calls in file

1
2
3
4
5
6
7
8
9
10
var _ = require('underscore');

var brandings = {
    "localhost": [ip.cidrSubnet('127.0.0.0/8')],
    "The Ohio State University": [ip.cidrSubnet('164.107.0.0/16'),
                                  ip.cidrSubnet('140.254.0.0/16'),
                                  ip.cidrSubnet('128.146.0.0/16'),
                                  ip.cidrSubnet('192.68.143.0/24'),
                                  ip.cidrSubnet('192.12.205.0/24')],
    "Colorado State University": [ip.cidrSubnet('129.82.0.0/16')]
fork icon32
star icon54
watch icon11

+ 7 other calls in file

143
144
145
146
147
148
149
150
151
152
this._currentExtIp4 = externalIP;
// do not add IPv6 support for UPnP
// await exec(util.wrapIptables(`sudo ip6tables -w -t nat -A FR_UPNP -j ${this._getNATChain()}`)).catch((err) => {});

const uuid = intfPlugin.networkConfig && intfPlugin.networkConfig.meta && intfPlugin.networkConfig.meta.uuid;
const internalCidrs = intState.ip4s.map(ip4 => ip.cidrSubnet(ip4));
const internalIPs = intState.ip4s.sort().filter((v, i, a) => a.indexOf(v) === i);
const internalNetworks = internalCidrs.map(internalCidr => `${internalCidr.networkAddress}/${internalCidr.subnetMaskLength}`).sort().filter((v, i, a) => a.indexOf(v) === i);
await this.generateConfig(uuid, extIntf, internalIPs, internalNetworks);
await exec(`sudo systemctl restart firerouter_upnpd@${this.name}`);
fork icon10
star icon9
watch icon0

86
87
88
89
90
91
92
93
94
95
try {
	if (rows.length>0) {
		if (req.body.type===5 || req.body.type===7) { // 5: ADDRESS, 7: NETWORK
			// We have two formats for the netmask (for example, 255.255.255.0 or /24).
			// We have to check if the object already exist independently of the netmask format.
			const net1 = (req.body.netmask[0]==='/') ? ip.cidrSubnet(`${req.body.address}${req.body.netmask}`) : ip.subnet(req.body.address, req.body.netmask);
			let net2 = {};
			for (row of rows) {
				net2 = (row.netmask[0] === '/') ? ip.cidrSubnet(`${row.address}${row.netmask}`) : ip.subnet(row.address, row.netmask);
				if (net1.subnetMaskLength===net2.subnetMaskLength)
fork icon4
star icon4
watch icon0

10
11
12
13
14
15
16
17
18
19
let groups = []
let currCidr = ip.cidrSubnet(config.cidr)
_.map(instance.cidr_blocks, block => {
  let group = {}
  // debug('Block: %j', block)
  let newCidr = ip.cidrSubnet(block)
  if ( allow == false ){
    check = currCidr.contains(newCidr.firstAddress) || currCidr.contains(newCidr.lastAddress) || newCidr.contains(currCidr.firstAddress) || newCidr.contains(currCidr.lastAddress);
  } else if ( allow ) {
    check = newCidr.contains(currCidr.firstAddress) && newCidr.contains(currCidr.lastAddress);
fork icon1
star icon3
watch icon19

+ 3 other calls in file

47
48
49
50
51
52
53
54
55
56
    const reg = /^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$/
    return reg.test(val);
}

//console.log("127.0.0.1 is private network?", ip.isPrivate('127.0.0.1'));
//let str = ip.cidrSubnet('192.168.1.134/26');
//console.log(str)
isCIDR(val: any): boolean {
    let str = val.split('/');
    if( !this.validationService.isBlank(str[0]) && !this.validationService.isBlank(str[1]) )
fork icon1
star icon1
watch icon1

+ 3 other calls in file

86
87
88
89
90
91
92
93
94
95
  }
}

class CIDR {
  constructor(range) {
    this.subnet = ip.cidrSubnet(range);
  }
  get ip() {
    return this.subnet.networkAddress;
  }
fork icon48
star icon0
watch icon2

21
22
23
24
25
26
27
28
29
30
// Check if already added
if (this.ranges[cidr]) {
    return;
}

var info = ip.cidrSubnet(cidr);

// Add
if (info) {
    this.ranges[cidr] = [ ip.toLong(info.firstAddress), ip.toLong(info.lastAddress) ];
fork icon7
star icon0
watch icon2

11
12
13
14
15
16
17
18
19
20
let groups = [];
let currCidr = ip.cidrSubnet(config.cidr);
_.map(instance.cidr_blocks, block => {
  let group = {};
  // debug('Block: %j', block)
  let newCidr = ip.cidrSubnet(block);
  if ( allow === false ){
    check = currCidr.contains(newCidr.firstAddress) || currCidr.contains(newCidr.lastAddress) || newCidr.contains(currCidr.firstAddress) || newCidr.contains(currCidr.lastAddress);
  } else if ( allow ) {
    check = newCidr.contains(currCidr.firstAddress) && newCidr.contains(currCidr.lastAddress);
fork icon1
star icon0
watch icon1

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
 * @public
 */

exports.create = function(cidr) {

  var n = objectAssign(Object.create(network), ip.cidrSubnet(cidr));

  n.cidr = cidr;
  n.firstAddressLong = ip.toLong(n.firstAddress);
  n.lastAddressLong = ip.toLong(n.lastAddress);
fork icon0
star icon9
watch icon2

78
79
80
81
82
83
84
85
86
87
88


router.get('/local', (req, res) => {
    res.json({
        local:
            process.env.SUBNET.split(',').some((v) => {
                return ip.cidrSubnet(v).contains(req.clientIp);
            }) || ip.isLoopback(req.clientIp),
    });
});

fork icon0
star icon0
watch icon0

79
80
81
82
83
84
85
86
87
88
    }
}

_joinRoom(peer) {
    if(ip.isPrivate(peer.ip)){
        peer.ip = ip.cidrSubnet(peer.ip + '/24').networkAddress; //broadcastAddress;
    }
 
    // if room doesn't exist, create it
    if (!this._rooms[peer.ip]) {
fork icon0
star icon0
watch icon0

+ 2 other calls in file