How to use the mask function from ip

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

87
88
89
90
91
92
93
94
95
96
//console.log(pool, "pool");
let arrayips = pool.split(';').filter(item => {return item != ""});
console.log(arrayips, "arrayips");
let i = 0;
let ipnot = ip.not(mask);
let networkIP = ip.mask(cidr, mask);
let broadcaseIP = ip.or(cidr, ipnot);
console.log(ipnot, networkIP, broadcaseIP);
for (i = 0; i < arrayips.length; i++) {
    let lineips = arrayips[i].split(',');
fork icon1
star icon1
watch icon1

17
18
19
20
21
22
23
24
25
26
var ip = require('ip')

module.exports = function (log, config) {

  function getBaseIp(addr, prefixLength) {
    return ip.mask(addr, ip.fromPrefixLen(prefixLength))
  }

  function parseRow(ipColumn) {
    // Ignore # lines
fork icon210
star icon0
watch icon1

391
392
393
394
395
396
397
398
399
400
  if (cidrParts.length !== 2)
    throw new Error('invalid CIDR subnet: ' + addr);

  var mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));

  return ip.mask(addr, mask);
};

ip.subnet = function(addr, mask) {
  var networkAddress = ip.toLong(ip.mask(addr, mask));
fork icon0
star icon0
watch icon1

+ 2 other calls in file

148
149
150
151
152
153
154
155
156
157
// Reset scanCancelled just in case
scanCancelled = false;

// Get local IP mask if not already defined
if (localIpMask === null) {
    localIpMask = ip.mask(ip.address(), ip.fromPrefixLen(24));
}

// Create new scan object with IP range and args
// Args will run a fast scan with OS detection and XML output, which will be parsed for us by node-nmap
fork icon0
star icon0
watch icon2

150
151
152
153
154
155
156
157
158
159
  res.send({'status': req.param('status') == 'on'});
},
ping: function(req, res) {
  var hosts = req.param('hosts');
  var mask = 24;
  var currentNetwork = ip.mask(ip.address(), ip.fromPrefixLen(24));

  child = exec("sudo nmap -sP " + currentNetwork + "/" + mask + " ; sudo arp-scan --localnet ; sudo nmap -sP " + currentNetwork + "/" + mask, function (error, stdout, stderr) {
    if (error !== null)
    {
fork icon0
star icon0
watch icon2

19
20
21
22
23
24
25
26
27
28
  if(iface.length > 0) ifacenetmask = iface[0].netmask;
}

// ip: separate out the network using the subnet mask
var ipnet = require('ip');
var network = ipnet.mask(`${ipaddress}`, `${ifacenetmask}`)

// morgan: generate apache style logs to the console
var morgan = require('morgan')
app.use(morgan('combined'));
fork icon0
star icon0
watch icon2