How to use the toLong function from ip

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

89
90
91
92
93
94
95
96
97
98
class SysManager {
  constructor() { // loglevel is already ignored
    if (instance == null) {
      log.info('Initializing SysManager')
      rclient.hdel("sys:network:info", "oper");
      this.multicastlow = iptool.toLong("224.0.0.0");
      this.multicasthigh = iptool.toLong("239.255.255.255");
      this.repo = {};
      this.ipIntfCache = new LRU({max: 4096, maxAge: 900 * 1000}); // reduce call to inMySubnets4/6 in getInterfaceViaIP4/6, which is CPU intensive, the cache will be flushed if network info is updated
      this.iptablesReady = false;
fork icon117
star icon463
watch icon0

+ 11 other calls in file

95
96
97
98
99
100
101
102
103
104
    }
    return ip;
}

function ip_to_long(ip) {
    return ip_module.toLong(unwrap_ipv6(ip));
}

async function retrieve_public_ip() {
    const IPIFY_TIMEOUT = 30 * 1000;
fork icon70
star icon229
watch icon17

62
63
64
65
66
67
68
69
70
71
  for (var i = addresses.length; i--;) {
    var address = addresses[i]
    if (address.family === 'IPv4' && !address.internal) {
      var subnet = ip.subnet(address.address, address.netmask)
      var current = ip.toLong(subnet.firstAddress)
      var last = ip.toLong(subnet.lastAddress) - 1
      while (current++ < last) result.push(ip.fromLong(current))
    }
  }
}
fork icon25
star icon122
watch icon0

106
107
108
109
110
111
112
113
114
115
const testRange = (ip, constraint, mode) => {
  const filteredSet = _.filter(getIps(), (constraint) => {
    if (constraint.length > 1) {
      const startIp = iputil.toLong(constraint[0])
      const endIp = iputil.toLong(constraint[1])
      const longIp = iputil.toLong(ip)
      return longIp >= startIp && longIp <= endIp
    } else {
      return ip === constraint[0]
    }
fork icon17
star icon60
watch icon0

+ 2 other calls in file

23
24
25
26
27
28
29
30
31
32
for (let i = addresses.length; i--; ) {
  const address = addresses[i];
  if (address.family === 'IPv4' && !address.internal && address.address.substring(0, 3) !== '169') {
    let subnet = ip.subnet(address.address, address.netmask);
    let current = ip.toLong(subnet.firstAddress);
    let last = ip.toLong(subnet.lastAddress) - 1;
    address.searchTruncated = false;

    if (last - current > 2296) {
      subnet = ip.subnet(address.address, '255.255.248.0');
fork icon2
star icon31
watch icon0

+ 11 other calls in file

28
29
30
31
32
33
34
35
36
37
  console.log(ip.isPrivate(ipaddr) ? 'Private IP:' : 'IP:', ipaddr);
} else if (id === 'ip') {
  if (ip.isPrivate(ret[0])) {
    console.log('Private IP:', ip.toLong(ret[0]));
  } else {
    console.log('IP2LONG: ' + ip.toLong(ret[0]));
    info.internetip(ret[0]);
    if (options.parent.chinese) {
      info.ipcn(ret[0])
    }
fork icon1
star icon1
watch icon2

+ 5 other calls in file

73
74
75
76
77
78
79
80
81
82
    if(ip.subnet(val[1], val[2]).contains(val[0])) return true;
    else return false;
}

isMaskInSubnet(val: any): boolean {
    console.log(ip.toLong(val[0]), ip.toLong(ip.cidrSubnet(val[1]).subnetMask), "子网掩码", "期望子网掩码")
    if(ip.toLong(val[0]) == ip.toLong(ip.cidrSubnet(val[1]).subnetMask)) return true;
    else return false;

}
fork icon1
star icon1
watch icon1

+ 7 other calls in file

18
19
20
21
22
23
24
25
26
27

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

  n.cidr = cidr;
  n.firstAddressLong = ip.toLong(n.firstAddress);
  n.lastAddressLong = ip.toLong(n.lastAddress);

  return n;

};
fork icon0
star icon9
watch icon2

+ 5 other calls in file

74
75
76
77
78
79
80
81
82
83

// match range
if (cidr.includes('-')) {
    const parts = cidr.split('-');
    const ipStart = ipLib.toLong(parts[0].trim());
    const ipEnd = ipLib.toLong(parts[1].trim());
    ranges.push([ipStart, ipEnd]);
}

// match a single ip or ips like (123.156)
fork icon0
star icon1
watch icon3

+ 7 other calls in file

25
26
27
28
29
30
31
32
33
34

    var info = ip.cidrSubnet(cidr);

    // Add
    if (info) {
        this.ranges[cidr] = [ ip.toLong(info.firstAddress), ip.toLong(info.lastAddress) ];
    }
};

Matcher.prototype.removeNetworkClass = function(cidr) {
fork icon7
star icon0
watch icon2

+ 3 other calls in file

100
101
102
103
104
105
106
107
108
109
110
111
})


//haetaan seuraava vapaa viereikkäin oleva IP-blokki 
const nextFreeIPBlock = (network, taken, size, role) => {
  const max = ip.toLong(network.hostMax)
  const min = ip.toLong(network.hostMin)


  //tarkistus, että haetaan vain 1-5 IP:tä, jos hakijana käyttäjä
  if (role === 'user' && (size < 1 || size > 5)) throw new Error('Invalid amount requested as ' + role)

fork icon2
star icon0
watch icon0

100
101
102
103
104
105
106
107
108
109
var country = range.country;

var curr = start;

// generate individual IPs at start of range
var bordermask = ip.toLong('0.0.0.255');
var endmask = ip.toLong('255.255.255.255');
var increment = 1;
while (curr < ((end & endmask) >>> 0) && ((curr & bordermask) >>> 0)) {
  pushTarget.push(
fork icon0
star icon1
watch icon0

+ 14 other calls in file

33
34
35
36
37
38
39
40
41
42
 * @param {String} toIp
 * @returns {String[]}
 */
const getIPsWithinRange = (fromIp, toIp) => {
  const from = ip.toLong(fromIp)
  const to = ip.toLong(toIp)
  const IPs = []
  for (let i = from; i <= to; i++) {
    IPs.push(ip.fromLong(i))
  }
fork icon1
star icon0
watch icon0

+ 5 other calls in file

45
46
47
48
49
50
51
52
53
var e = this.entry;

if (e.lastIp) {
  r = ++e.lastIp;

  if (r >= Ip.toLong(e.dval.end)) {
    r = undefined;
  }
}
fork icon1
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
15
16
17
const serviceToken = process.env.SERVICE_TOKEN;




const generator = new FlakeId({
    // Prevent multiple servers collision
    id: ip.toLong(ip.address()) % 1024,
});


function capTransactions(transactions, maximumAmount) {
    let total = new Decimal(0);
fork icon0
star icon0
watch icon0

30
31
32
33
34
35
36
37
38
39

let cnt = 0;
let list = [];

networks.map(async (network) => {
    for(let i = ip.toLong(network.firstAddress), l = ip.toLong(network.lastAddress); i < l + 1; i++){
        let address = ip.fromLong(i)
        if (myAddress.indexOf(address) != -1) continue;

        cnt++;
fork icon0
star icon0
watch icon0

237
238
239
240
241
242
243
244
245
246
           seed: this.id.hashCode()
       })

// console.dir(req.headers);
       let from =  req.headers['client-ip'] || req.headers['x-forwarded-for'] || "";
       if(from) from = ip.toLong(from) % 1000;

       this.name = {
           model: ua.device.model,
           os: ua.os.name,
fork icon0
star icon0
watch icon0

+ 2 other calls in file

395
396
397
398
399
400
401
402
403
404

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

ip.subnet = function(addr, mask) {
  var networkAddress = ip.toLong(ip.mask(addr, mask));

  // Calculate the mask's length.
  var maskBuffer = ip.toBuffer(mask);
  var maskLength = 0;
fork icon0
star icon0
watch icon1

+ 5 other calls in file