|
@@ -38,12 +38,12 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
runParseIpRange: function (input, args) {
|
|
runParseIpRange: function (input, args) {
|
|
- var includeNetworkInfo = args[0],
|
|
|
|
|
|
+ let includeNetworkInfo = args[0],
|
|
enumerateAddresses = args[1],
|
|
enumerateAddresses = args[1],
|
|
allowLargeList = args[2];
|
|
allowLargeList = args[2];
|
|
|
|
|
|
// Check what type of input we are looking at
|
|
// Check what type of input we are looking at
|
|
- var ipv4CidrRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/,
|
|
|
|
|
|
+ let ipv4CidrRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/,
|
|
ipv4RangeRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*-\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/,
|
|
ipv4RangeRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*-\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/,
|
|
ipv6CidrRegex = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\/(\d\d?\d?)\s*$/i,
|
|
ipv6CidrRegex = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\/(\d\d?\d?)\s*$/i,
|
|
ipv6RangeRegex = /^\s*(((?=.*::)(?!.*::[^-]+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*-\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\17)::|:\b|(?![\dA-F])))|(?!\16\17)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
|
|
ipv6RangeRegex = /^\s*(((?=.*::)(?!.*::[^-]+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*-\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\17)::|:\b|(?![\dA-F])))|(?!\16\17)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
|
|
@@ -82,11 +82,11 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
runParseIPv6: function (input, args) {
|
|
runParseIPv6: function (input, args) {
|
|
- var match,
|
|
|
|
|
|
+ let match,
|
|
output = "";
|
|
output = "";
|
|
|
|
|
|
if ((match = IP.IPV6_REGEX.exec(input))) {
|
|
if ((match = IP.IPV6_REGEX.exec(input))) {
|
|
- var ipv6 = IP._strToIpv6(match[1]),
|
|
|
|
|
|
+ let ipv6 = IP._strToIpv6(match[1]),
|
|
longhand = IP._ipv6ToStr(ipv6),
|
|
longhand = IP._ipv6ToStr(ipv6),
|
|
shorthand = IP._ipv6ToStr(ipv6, true);
|
|
shorthand = IP._ipv6ToStr(ipv6, true);
|
|
|
|
|
|
@@ -126,7 +126,7 @@ const IP = {
|
|
} else if (ipv6[0] === 0x2001 && ipv6[1] === 0) {
|
|
} else if (ipv6[0] === 0x2001 && ipv6[1] === 0) {
|
|
// Teredo tunneling
|
|
// Teredo tunneling
|
|
output += "\nTeredo tunneling IPv6 address detected\n";
|
|
output += "\nTeredo tunneling IPv6 address detected\n";
|
|
- var serverIpv4 = (ipv6[2] << 16) + ipv6[3],
|
|
|
|
|
|
+ let serverIpv4 = (ipv6[2] << 16) + ipv6[3],
|
|
udpPort = (~ipv6[5]) & 0xffff,
|
|
udpPort = (~ipv6[5]) & 0xffff,
|
|
clientIpv4 = ~((ipv6[6] << 16) + ipv6[7]),
|
|
clientIpv4 = ~((ipv6[6] << 16) + ipv6[7]),
|
|
flagCone = (ipv6[4] >>> 15) & 1,
|
|
flagCone = (ipv6[4] >>> 15) & 1,
|
|
@@ -190,7 +190,7 @@ const IP = {
|
|
output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." +
|
|
output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." +
|
|
"\n6to4 prefix range: 2002::/16";
|
|
"\n6to4 prefix range: 2002::/16";
|
|
|
|
|
|
- var v4Addr = IP._ipv4ToStr((ipv6[1] << 16) + ipv6[2]),
|
|
|
|
|
|
+ let v4Addr = IP._ipv4ToStr((ipv6[1] << 16) + ipv6[2]),
|
|
slaId = ipv6[3],
|
|
slaId = ipv6[3],
|
|
interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16),
|
|
interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16),
|
|
interfaceId = new BigInteger(interfaceIdStr, 16);
|
|
interfaceId = new BigInteger(interfaceIdStr, 16);
|
|
@@ -218,7 +218,7 @@ const IP = {
|
|
if ((ipv6[5] & 0xff === 0xff) && (ipv6[6] >>> 8 === 0xfe)) {
|
|
if ((ipv6[5] & 0xff === 0xff) && (ipv6[6] >>> 8 === 0xfe)) {
|
|
output += "\n\nThis IPv6 address contains a modified EUI-64 address, identified by the presence of FF:FE in the 12th and 13th octets.";
|
|
output += "\n\nThis IPv6 address contains a modified EUI-64 address, identified by the presence of FF:FE in the 12th and 13th octets.";
|
|
|
|
|
|
- var intIdent = Utils.hex(ipv6[4] >>> 8) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" +
|
|
|
|
|
|
+ let intIdent = Utils.hex(ipv6[4] >>> 8) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" +
|
|
Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[5] & 0xff) + ":" +
|
|
Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[5] & 0xff) + ":" +
|
|
Utils.hex(ipv6[6] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" +
|
|
Utils.hex(ipv6[6] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" +
|
|
Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff),
|
|
Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff),
|
|
@@ -249,16 +249,18 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
runChangeIpFormat: function(input, args) {
|
|
runChangeIpFormat: function(input, args) {
|
|
- var inFormat = args[0],
|
|
|
|
|
|
+ let inFormat = args[0],
|
|
outFormat = args[1],
|
|
outFormat = args[1],
|
|
lines = input.split("\n"),
|
|
lines = input.split("\n"),
|
|
output = "",
|
|
output = "",
|
|
j = 0;
|
|
j = 0;
|
|
|
|
|
|
|
|
|
|
- for (var i = 0; i < lines.length; i++) {
|
|
|
|
|
|
+ for (let i = 0; i < lines.length; i++) {
|
|
if (lines[i] === "") continue;
|
|
if (lines[i] === "") continue;
|
|
- var baIp = [];
|
|
|
|
|
|
+ let baIp = [];
|
|
|
|
+ let octets;
|
|
|
|
+ let decimal;
|
|
|
|
|
|
if (inFormat === outFormat) {
|
|
if (inFormat === outFormat) {
|
|
output += lines[i] + "\n";
|
|
output += lines[i] + "\n";
|
|
@@ -268,13 +270,13 @@ const IP = {
|
|
// Convert to byte array IP from input format
|
|
// Convert to byte array IP from input format
|
|
switch (inFormat) {
|
|
switch (inFormat) {
|
|
case "Dotted Decimal":
|
|
case "Dotted Decimal":
|
|
- var octets = lines[i].split(".");
|
|
|
|
|
|
+ octets = lines[i].split(".");
|
|
for (j = 0; j < octets.length; j++) {
|
|
for (j = 0; j < octets.length; j++) {
|
|
baIp.push(parseInt(octets[j], 10));
|
|
baIp.push(parseInt(octets[j], 10));
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case "Decimal":
|
|
case "Decimal":
|
|
- var decimal = lines[i].toString();
|
|
|
|
|
|
+ decimal = lines[i].toString();
|
|
baIp.push(decimal >> 24 & 255);
|
|
baIp.push(decimal >> 24 & 255);
|
|
baIp.push(decimal >> 16 & 255);
|
|
baIp.push(decimal >> 16 & 255);
|
|
baIp.push(decimal >> 8 & 255);
|
|
baIp.push(decimal >> 8 & 255);
|
|
@@ -287,21 +289,25 @@ const IP = {
|
|
throw "Unsupported input IP format";
|
|
throw "Unsupported input IP format";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ let ddIp;
|
|
|
|
+ let decIp;
|
|
|
|
+ let hexIp;
|
|
|
|
+
|
|
// Convert byte array IP to output format
|
|
// Convert byte array IP to output format
|
|
switch (outFormat) {
|
|
switch (outFormat) {
|
|
case "Dotted Decimal":
|
|
case "Dotted Decimal":
|
|
- var ddIp = "";
|
|
|
|
|
|
+ ddIp = "";
|
|
for (j = 0; j < baIp.length; j++) {
|
|
for (j = 0; j < baIp.length; j++) {
|
|
ddIp += baIp[j] + ".";
|
|
ddIp += baIp[j] + ".";
|
|
}
|
|
}
|
|
output += ddIp.slice(0, ddIp.length-1) + "\n";
|
|
output += ddIp.slice(0, ddIp.length-1) + "\n";
|
|
break;
|
|
break;
|
|
case "Decimal":
|
|
case "Decimal":
|
|
- var decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
|
|
|
|
|
+ decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
|
output += decIp.toString() + "\n";
|
|
output += decIp.toString() + "\n";
|
|
break;
|
|
break;
|
|
case "Hex":
|
|
case "Hex":
|
|
- var hexIp = "";
|
|
|
|
|
|
+ hexIp = "";
|
|
for (j = 0; j < baIp.length; j++) {
|
|
for (j = 0; j < baIp.length; j++) {
|
|
hexIp += Utils.hex(baIp[j]);
|
|
hexIp += Utils.hex(baIp[j]);
|
|
}
|
|
}
|
|
@@ -340,7 +346,7 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
runGroupIps: function(input, args) {
|
|
runGroupIps: function(input, args) {
|
|
- var delim = Utils.charRep[args[0]],
|
|
|
|
|
|
+ let delim = Utils.charRep[args[0]],
|
|
cidr = args[1],
|
|
cidr = args[1],
|
|
onlySubnets = args[2],
|
|
onlySubnets = args[2],
|
|
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
|
|
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
|
|
@@ -352,14 +358,15 @@ const IP = {
|
|
output = "",
|
|
output = "",
|
|
ip = null,
|
|
ip = null,
|
|
network = null,
|
|
network = null,
|
|
- networkStr = "";
|
|
|
|
|
|
+ networkStr = "",
|
|
|
|
+ i;
|
|
|
|
|
|
if (cidr < 0 || cidr > 127) {
|
|
if (cidr < 0 || cidr > 127) {
|
|
return "CIDR must be less than 32 for IPv4 or 128 for IPv6";
|
|
return "CIDR must be less than 32 for IPv4 or 128 for IPv6";
|
|
}
|
|
}
|
|
|
|
|
|
// Parse all IPs and add to network dictionary
|
|
// Parse all IPs and add to network dictionary
|
|
- for (var i = 0; i < ips.length; i++) {
|
|
|
|
|
|
+ for (i = 0; i < ips.length; i++) {
|
|
if ((match = IP.IPV4_REGEX.exec(ips[i]))) {
|
|
if ((match = IP.IPV4_REGEX.exec(ips[i]))) {
|
|
ip = IP._strToIpv4(match[1]) >>> 0;
|
|
ip = IP._strToIpv4(match[1]) >>> 0;
|
|
network = ip & ipv4Mask;
|
|
network = ip & ipv4Mask;
|
|
@@ -374,7 +381,7 @@ const IP = {
|
|
network = [];
|
|
network = [];
|
|
networkStr = "";
|
|
networkStr = "";
|
|
|
|
|
|
- for (var j = 0; j < 8; j++) {
|
|
|
|
|
|
+ for (let j = 0; j < 8; j++) {
|
|
network.push(ip[j] & ipv6Mask[j]);
|
|
network.push(ip[j] & ipv6Mask[j]);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -434,7 +441,7 @@ const IP = {
|
|
* @returns {html}
|
|
* @returns {html}
|
|
*/
|
|
*/
|
|
runParseIPv4Header: function(input, args) {
|
|
runParseIPv4Header: function(input, args) {
|
|
- var format = args[0],
|
|
|
|
|
|
+ let format = args[0],
|
|
output;
|
|
output;
|
|
|
|
|
|
if (format === "Hex") {
|
|
if (format === "Hex") {
|
|
@@ -445,7 +452,7 @@ const IP = {
|
|
return "Unrecognised input format.";
|
|
return "Unrecognised input format.";
|
|
}
|
|
}
|
|
|
|
|
|
- var version = (input[0] >>> 4) & 0x0f,
|
|
|
|
|
|
+ let version = (input[0] >>> 4) & 0x0f,
|
|
ihl = input[0] & 0x0f,
|
|
ihl = input[0] & 0x0f,
|
|
dscp = (input[1] >>> 2) & 0x3f,
|
|
dscp = (input[1] >>> 2) & 0x3f,
|
|
ecn = input[1] & 0x03,
|
|
ecn = input[1] & 0x03,
|
|
@@ -471,15 +478,15 @@ const IP = {
|
|
ihl = ihl + " (Error: this should always be at least 5)";
|
|
ihl = ihl + " (Error: this should always be at least 5)";
|
|
} else if (ihl > 5) {
|
|
} else if (ihl > 5) {
|
|
// sort out options...
|
|
// sort out options...
|
|
- var optionsLen = ihl * 4 - 20;
|
|
|
|
|
|
+ const optionsLen = ihl * 4 - 20;
|
|
options = input.slice(20, optionsLen + 20);
|
|
options = input.slice(20, optionsLen + 20);
|
|
}
|
|
}
|
|
|
|
|
|
// Protocol
|
|
// Protocol
|
|
- var protocolInfo = IP._protocolLookup[protocol] || {keyword: "", protocol: ""};
|
|
|
|
|
|
+ const protocolInfo = IP._protocolLookup[protocol] || {keyword: "", protocol: ""};
|
|
|
|
|
|
// Checksum
|
|
// Checksum
|
|
- var correctChecksum = Checksum.runTCPIP(checksumHeader, []),
|
|
|
|
|
|
+ let correctChecksum = Checksum.runTCPIP(checksumHeader, []),
|
|
givenChecksum = Utils.hex(checksum),
|
|
givenChecksum = Utils.hex(checksum),
|
|
checksumResult;
|
|
checksumResult;
|
|
if (correctChecksum === givenChecksum) {
|
|
if (correctChecksum === givenChecksum) {
|
|
@@ -534,7 +541,7 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
_ipv4CidrRange: function(cidr, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
|
_ipv4CidrRange: function(cidr, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
|
- var output = "",
|
|
|
|
|
|
+ let output = "",
|
|
network = IP._strToIpv4(cidr[1]),
|
|
network = IP._strToIpv4(cidr[1]),
|
|
cidrRange = parseInt(cidr[2], 10);
|
|
cidrRange = parseInt(cidr[2], 10);
|
|
|
|
|
|
@@ -542,7 +549,7 @@ const IP = {
|
|
return "IPv4 CIDR must be less than 32";
|
|
return "IPv4 CIDR must be less than 32";
|
|
}
|
|
}
|
|
|
|
|
|
- var mask = ~(0xFFFFFFFF >>> cidrRange),
|
|
|
|
|
|
+ let mask = ~(0xFFFFFFFF >>> cidrRange),
|
|
ip1 = network & mask,
|
|
ip1 = network & mask,
|
|
ip2 = ip1 | ~mask;
|
|
ip2 = ip1 | ~mask;
|
|
|
|
|
|
@@ -574,7 +581,7 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
_ipv6CidrRange: function(cidr, includeNetworkInfo) {
|
|
_ipv6CidrRange: function(cidr, includeNetworkInfo) {
|
|
- var output = "",
|
|
|
|
|
|
+ let output = "",
|
|
network = IP._strToIpv6(cidr[1]),
|
|
network = IP._strToIpv6(cidr[1]),
|
|
cidrRange = parseInt(cidr[cidr.length-1], 10);
|
|
cidrRange = parseInt(cidr[cidr.length-1], 10);
|
|
|
|
|
|
@@ -582,19 +589,19 @@ const IP = {
|
|
return "IPv6 CIDR must be less than 128";
|
|
return "IPv6 CIDR must be less than 128";
|
|
}
|
|
}
|
|
|
|
|
|
- var mask = IP._genIpv6Mask(cidrRange),
|
|
|
|
|
|
+ let mask = IP._genIpv6Mask(cidrRange),
|
|
ip1 = new Array(8),
|
|
ip1 = new Array(8),
|
|
ip2 = new Array(8),
|
|
ip2 = new Array(8),
|
|
totalDiff = "",
|
|
totalDiff = "",
|
|
total = new Array(128);
|
|
total = new Array(128);
|
|
|
|
|
|
- for (var i = 0; i < 8; i++) {
|
|
|
|
|
|
+ for (let i = 0; i < 8; i++) {
|
|
ip1[i] = network[i] & mask[i];
|
|
ip1[i] = network[i] & mask[i];
|
|
ip2[i] = ip1[i] | (~mask[i] & 0x0000FFFF);
|
|
ip2[i] = ip1[i] | (~mask[i] & 0x0000FFFF);
|
|
totalDiff = (ip2[i] - ip1[i]).toString(2);
|
|
totalDiff = (ip2[i] - ip1[i]).toString(2);
|
|
|
|
|
|
if (totalDiff !== "0") {
|
|
if (totalDiff !== "0") {
|
|
- for (var n = 0; n < totalDiff.length; n++) {
|
|
|
|
|
|
+ for (let n = 0; n < totalDiff.length; n++) {
|
|
total[i*16 + 16-(totalDiff.length-n)] = totalDiff[n];
|
|
total[i*16 + 16-(totalDiff.length-n)] = totalDiff[n];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -621,10 +628,10 @@ const IP = {
|
|
* @returns {number[]}
|
|
* @returns {number[]}
|
|
*/
|
|
*/
|
|
_genIpv6Mask: function(cidr) {
|
|
_genIpv6Mask: function(cidr) {
|
|
- var mask = new Array(8),
|
|
|
|
|
|
+ let mask = new Array(8),
|
|
shift;
|
|
shift;
|
|
|
|
|
|
- for (var i = 0; i < 8; i++) {
|
|
|
|
|
|
+ for (let i = 0; i < 8; i++) {
|
|
if (cidr > ((i+1)*16)) {
|
|
if (cidr > ((i+1)*16)) {
|
|
mask[i] = 0x0000FFFF;
|
|
mask[i] = 0x0000FFFF;
|
|
} else {
|
|
} else {
|
|
@@ -650,12 +657,12 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
_ipv4HyphenatedRange: function(range, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
|
_ipv4HyphenatedRange: function(range, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
|
- var output = "",
|
|
|
|
|
|
+ let output = "",
|
|
ip1 = IP._strToIpv4(range[1]),
|
|
ip1 = IP._strToIpv4(range[1]),
|
|
ip2 = IP._strToIpv4(range[2]);
|
|
ip2 = IP._strToIpv4(range[2]);
|
|
|
|
|
|
// Calculate mask
|
|
// Calculate mask
|
|
- var diff = ip1 ^ ip2,
|
|
|
|
|
|
+ let diff = ip1 ^ ip2,
|
|
cidr = 32,
|
|
cidr = 32,
|
|
mask = 0;
|
|
mask = 0;
|
|
|
|
|
|
@@ -666,7 +673,7 @@ const IP = {
|
|
}
|
|
}
|
|
|
|
|
|
mask = ~mask >>> 0;
|
|
mask = ~mask >>> 0;
|
|
- var network = ip1 & mask,
|
|
|
|
|
|
+ let network = ip1 & mask,
|
|
subIp1 = network & mask,
|
|
subIp1 = network & mask,
|
|
subIp2 = subIp1 | ~mask;
|
|
subIp2 = subIp1 | ~mask;
|
|
|
|
|
|
@@ -701,21 +708,22 @@ const IP = {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
_ipv6HyphenatedRange: function(range, includeNetworkInfo) {
|
|
_ipv6HyphenatedRange: function(range, includeNetworkInfo) {
|
|
- var output = "",
|
|
|
|
|
|
+ let output = "",
|
|
ip1 = IP._strToIpv6(range[1]),
|
|
ip1 = IP._strToIpv6(range[1]),
|
|
ip2 = IP._strToIpv6(range[14]);
|
|
ip2 = IP._strToIpv6(range[14]);
|
|
|
|
|
|
- var t = "",
|
|
|
|
- total = new Array(128);
|
|
|
|
|
|
+ let t = "",
|
|
|
|
+ total = new Array(128),
|
|
|
|
+ i;
|
|
|
|
|
|
// Initialise total array to "0"
|
|
// Initialise total array to "0"
|
|
- for (var i = 0; i < 128; i++)
|
|
|
|
|
|
+ for (i = 0; i < 128; i++)
|
|
total[i] = "0";
|
|
total[i] = "0";
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
for (i = 0; i < 8; i++) {
|
|
t = (ip2[i] - ip1[i]).toString(2);
|
|
t = (ip2[i] - ip1[i]).toString(2);
|
|
if (t !== "0") {
|
|
if (t !== "0") {
|
|
- for (var n = 0; n < t.length; n++) {
|
|
|
|
|
|
+ for (let n = 0; n < t.length; n++) {
|
|
total[i*16 + 16-(t.length-n)] = t[n];
|
|
total[i*16 + 16-(t.length-n)] = t[n];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -743,7 +751,7 @@ const IP = {
|
|
* IP._strToIpv4("10.10.0.0");
|
|
* IP._strToIpv4("10.10.0.0");
|
|
*/
|
|
*/
|
|
_strToIpv4: function (ipStr) {
|
|
_strToIpv4: function (ipStr) {
|
|
- var blocks = ipStr.split("."),
|
|
|
|
|
|
+ let blocks = ipStr.split("."),
|
|
numBlocks = parseBlocks(blocks),
|
|
numBlocks = parseBlocks(blocks),
|
|
result = 0;
|
|
result = 0;
|
|
|
|
|
|
@@ -761,8 +769,8 @@ const IP = {
|
|
if (blocks.length !== 4)
|
|
if (blocks.length !== 4)
|
|
throw "More than 4 blocks.";
|
|
throw "More than 4 blocks.";
|
|
|
|
|
|
- var numBlocks = [];
|
|
|
|
- for (var i = 0; i < 4; i++) {
|
|
|
|
|
|
+ const numBlocks = [];
|
|
|
|
+ for (let i = 0; i < 4; i++) {
|
|
numBlocks[i] = parseInt(blocks[i], 10);
|
|
numBlocks[i] = parseInt(blocks[i], 10);
|
|
if (numBlocks[i] < 0 || numBlocks[i] > 255)
|
|
if (numBlocks[i] < 0 || numBlocks[i] > 255)
|
|
throw "Block out of range.";
|
|
throw "Block out of range.";
|
|
@@ -784,7 +792,7 @@ const IP = {
|
|
* IP._ipv4ToStr(168427520);
|
|
* IP._ipv4ToStr(168427520);
|
|
*/
|
|
*/
|
|
_ipv4ToStr: function(ipInt) {
|
|
_ipv4ToStr: function(ipInt) {
|
|
- var blockA = (ipInt >> 24) & 255,
|
|
|
|
|
|
+ let blockA = (ipInt >> 24) & 255,
|
|
blockB = (ipInt >> 16) & 255,
|
|
blockB = (ipInt >> 16) & 255,
|
|
blockC = (ipInt >> 8) & 255,
|
|
blockC = (ipInt >> 8) & 255,
|
|
blockD = ipInt & 255;
|
|
blockD = ipInt & 255;
|
|
@@ -805,12 +813,12 @@ const IP = {
|
|
* IP._strToIpv6("ff00::1111:2222");
|
|
* IP._strToIpv6("ff00::1111:2222");
|
|
*/
|
|
*/
|
|
_strToIpv6: function(ipStr) {
|
|
_strToIpv6: function(ipStr) {
|
|
- var blocks = ipStr.split(":"),
|
|
|
|
|
|
+ let blocks = ipStr.split(":"),
|
|
numBlocks = parseBlocks(blocks),
|
|
numBlocks = parseBlocks(blocks),
|
|
j = 0,
|
|
j = 0,
|
|
ipv6 = new Array(8);
|
|
ipv6 = new Array(8);
|
|
|
|
|
|
- for (var i = 0; i < 8; i++) {
|
|
|
|
|
|
+ for (let i = 0; i < 8; i++) {
|
|
if (isNaN(numBlocks[j])) {
|
|
if (isNaN(numBlocks[j])) {
|
|
ipv6[i] = 0;
|
|
ipv6[i] = 0;
|
|
if (i === (8-numBlocks.slice(j).length)) j++;
|
|
if (i === (8-numBlocks.slice(j).length)) j++;
|
|
@@ -827,8 +835,8 @@ const IP = {
|
|
function parseBlocks(blocks) {
|
|
function parseBlocks(blocks) {
|
|
if (blocks.length < 3 || blocks.length > 8)
|
|
if (blocks.length < 3 || blocks.length > 8)
|
|
throw "Badly formatted IPv6 address.";
|
|
throw "Badly formatted IPv6 address.";
|
|
- var numBlocks = [];
|
|
|
|
- for (var i = 0; i < blocks.length; i++) {
|
|
|
|
|
|
+ const numBlocks = [];
|
|
|
|
+ for (let i = 0; i < blocks.length; i++) {
|
|
numBlocks[i] = parseInt(blocks[i], 16);
|
|
numBlocks[i] = parseInt(blocks[i], 16);
|
|
if (numBlocks[i] < 0 || numBlocks[i] > 65535)
|
|
if (numBlocks[i] < 0 || numBlocks[i] > 65535)
|
|
throw "Block out of range.";
|
|
throw "Block out of range.";
|
|
@@ -854,11 +862,11 @@ const IP = {
|
|
* IP._ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], false);
|
|
* IP._ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], false);
|
|
*/
|
|
*/
|
|
_ipv6ToStr: function(ipv6, compact) {
|
|
_ipv6ToStr: function(ipv6, compact) {
|
|
- var output = "",
|
|
|
|
|
|
+ let output = "",
|
|
i = 0;
|
|
i = 0;
|
|
|
|
|
|
if (compact) {
|
|
if (compact) {
|
|
- var start = -1,
|
|
|
|
|
|
+ let start = -1,
|
|
end = -1,
|
|
end = -1,
|
|
s = 0,
|
|
s = 0,
|
|
e = -1;
|
|
e = -1;
|
|
@@ -908,7 +916,7 @@ const IP = {
|
|
* IP._generateIpv4Range(1, 3);
|
|
* IP._generateIpv4Range(1, 3);
|
|
*/
|
|
*/
|
|
_generateIpv4Range: function(ip, endIp) {
|
|
_generateIpv4Range: function(ip, endIp) {
|
|
- var range = [];
|
|
|
|
|
|
+ const range = [];
|
|
if (endIp >= ip) {
|
|
if (endIp >= ip) {
|
|
for (; ip <= endIp; ip++) {
|
|
for (; ip <= endIp; ip++) {
|
|
range.push(IP._ipv4ToStr(ip));
|
|
range.push(IP._ipv4ToStr(ip));
|