Made variables non-private, and followed convention for the references to the IP lib.

This commit is contained in:
Callum Fraser 2018-05-16 22:32:46 +01:00
parent ea36687205
commit 3ba12ae9ac
7 changed files with 70 additions and 70 deletions

View file

@ -6,7 +6,7 @@
import Operation from "../Operation";
import Utils from "../Utils";
import {_ipv6ToStr, _genIpv6Mask, IPV4_REGEX, _strToIpv6, _ipv4ToStr, IPV6_REGEX, _strToIpv4} from "../lib/Ip";
import {ipv6ToStr, genIpv6Mask, IPV4_REGEX, strToIpv6, ipv4ToStr, IPV6_REGEX, strToIpv4} from "../lib/Ip.mjs";
/**
* Group IP addresses operation
@ -53,7 +53,7 @@ class GroupIPAddresses extends Operation {
cidr = args[1],
onlySubnets = args[2],
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
ipv6Mask = _genIpv6Mask(cidr),
ipv6Mask = genIpv6Mask(cidr),
ips = input.split(delim),
ipv4Networks = {},
ipv6Networks = {};
@ -71,7 +71,7 @@ class GroupIPAddresses extends Operation {
// Parse all IPs and add to network dictionary
for (i = 0; i < ips.length; i++) {
if ((match = IPV4_REGEX.exec(ips[i]))) {
ip = _strToIpv4(match[1]) >>> 0;
ip = strToIpv4(match[1]) >>> 0;
network = ip & ipv4Mask;
if (ipv4Networks.hasOwnProperty(network)) {
@ -80,7 +80,7 @@ class GroupIPAddresses extends Operation {
ipv4Networks[network] = [ip];
}
} else if ((match = IPV6_REGEX.exec(ips[i]))) {
ip = _strToIpv6(match[1]);
ip = strToIpv6(match[1]);
network = [];
networkStr = "";
@ -88,7 +88,7 @@ class GroupIPAddresses extends Operation {
network.push(ip[j] & ipv6Mask[j]);
}
networkStr = _ipv6ToStr(network, true);
networkStr = ipv6ToStr(network, true);
if (ipv6Networks.hasOwnProperty(networkStr)) {
ipv6Networks[networkStr].push(ip);
@ -102,11 +102,11 @@ class GroupIPAddresses extends Operation {
for (network in ipv4Networks) {
ipv4Networks[network] = ipv4Networks[network].sort();
output += _ipv4ToStr(network) + "/" + cidr + "\n";
output += ipv4ToStr(network) + "/" + cidr + "\n";
if (!onlySubnets) {
for (i = 0; i < ipv4Networks[network].length; i++) {
output += " " + _ipv4ToStr(ipv4Networks[network][i]) + "\n";
output += " " + ipv4ToStr(ipv4Networks[network][i]) + "\n";
}
output += "\n";
}
@ -120,7 +120,7 @@ class GroupIPAddresses extends Operation {
if (!onlySubnets) {
for (i = 0; i < ipv6Networks[networkStr].length; i++) {
output += " " + _ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
output += " " + ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
}
output += "\n";
}