|
@@ -3,6 +3,7 @@
|
|
|
*
|
|
|
* @author picapi
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
+ * @author Klaxon [klaxon@veyr.com]
|
|
|
* @copyright Crown Copyright 2016
|
|
|
* @license Apache-2.0
|
|
|
*/
|
|
@@ -110,7 +111,7 @@ export function ipv6CidrRange(cidr, includeNetworkInfo) {
|
|
|
*/
|
|
|
export function ipv4HyphenatedRange(range, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
|
|
const ip1 = strToIpv4(range[0].split("-")[0].trim()),
|
|
|
- ip2 = strToIpv4(range[0].split("-")[1].trim());
|
|
|
+ ip2 = strToIpv4(range[0].split("-")[1].trim());
|
|
|
|
|
|
let output = "";
|
|
|
|
|
@@ -200,27 +201,29 @@ export function ipv6HyphenatedRange(range, includeNetworkInfo) {
|
|
|
*/
|
|
|
export function ipv4ListedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
|
|
|
|
|
- var ipv4List = match[0].split("\n");
|
|
|
+ let ipv4List = match[0].split("\n");
|
|
|
ipv4List = ipv4List.filter(Boolean);
|
|
|
|
|
|
- var ipv4CidrList = ipv4List.filter( function(a) { return a.includes("/")});
|
|
|
+ const ipv4CidrList = ipv4List.filter(function(a) {
|
|
|
+ return a.includes("/");
|
|
|
+ });
|
|
|
for (let i = 0; i < ipv4CidrList.length; i++) {
|
|
|
- let network = strToIpv4(ipv4CidrList[i].split("/")[0]);
|
|
|
- let cidrRange = parseInt(ipv4CidrList[i].split("/")[1]);
|
|
|
+ const network = strToIpv4(ipv4CidrList[i].split("/")[0]);
|
|
|
+ const cidrRange = parseInt(ipv4CidrList[i].split("/")[1], 10);
|
|
|
if (cidrRange < 0 || cidrRange > 31) {
|
|
|
return "IPv4 CIDR must be less than 32";
|
|
|
}
|
|
|
- let mask = ~(0xFFFFFFFF >>> cidrRange),
|
|
|
+ const mask = ~(0xFFFFFFFF >>> cidrRange),
|
|
|
cidrIp1 = network & mask,
|
|
|
cidrIp2 = cidrIp1 | ~mask;
|
|
|
- ipv4List.splice(ipv4List.indexOf(ipv4CidrList[i]),1);
|
|
|
+ ipv4List.splice(ipv4List.indexOf(ipv4CidrList[i]), 1);
|
|
|
ipv4List.push(ipv4ToStr(cidrIp1), ipv4ToStr(cidrIp2));
|
|
|
}
|
|
|
|
|
|
ipv4List = ipv4List.sort(ipv4Compare);
|
|
|
- let ip1 = ipv4List[0];
|
|
|
- let ip2 = ipv4List[ipv4List.length - 1];
|
|
|
- let range = [ip1 + " - " + ip2]
|
|
|
+ const ip1 = ipv4List[0];
|
|
|
+ const ip2 = ipv4List[ipv4List.length - 1];
|
|
|
+ const range = [ip1 + " - " + ip2];
|
|
|
return ipv4HyphenatedRange(range, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
|
|
}
|
|
|
|
|
@@ -234,38 +237,42 @@ export function ipv4ListedRange(match, includeNetworkInfo, enumerateAddresses, a
|
|
|
*/
|
|
|
export function ipv6ListedRange(match, includeNetworkInfo) {
|
|
|
|
|
|
- var ipv6List = match[0].split("\n");
|
|
|
- ipv6List = ipv6List.filter(function(str) {return str.trim();});
|
|
|
+ let ipv6List = match[0].split("\n");
|
|
|
+ ipv6List = ipv6List.filter(function(str) {
|
|
|
+ return str.trim();
|
|
|
+ });
|
|
|
for (let i =0; i < ipv6List.length; i++){
|
|
|
ipv6List[i] = ipv6List[i].trim();
|
|
|
}
|
|
|
- var ipv6CidrList = ipv6List.filter( function(a) { return a.includes("/")});
|
|
|
+ const ipv6CidrList = ipv6List.filter(function(a) {
|
|
|
+ return a.includes("/");
|
|
|
+ });
|
|
|
|
|
|
for (let i = 0; i < ipv6CidrList.length; i++) {
|
|
|
|
|
|
- let network = strToIpv6(ipv6CidrList[i].split("/")[0]);
|
|
|
- let cidrRange = parseInt(ipv6CidrList[i].split("/")[1]);
|
|
|
+ const network = strToIpv6(ipv6CidrList[i].split("/")[0]);
|
|
|
+ const cidrRange = parseInt(ipv6CidrList[i].split("/")[1], 10);
|
|
|
|
|
|
if (cidrRange < 0 || cidrRange > 127) {
|
|
|
return "IPv6 CIDR must be less than 128";
|
|
|
}
|
|
|
|
|
|
- let cidrIp1 = new Array(8),
|
|
|
+ const cidrIp1 = new Array(8),
|
|
|
cidrIp2 = new Array(8);
|
|
|
|
|
|
- let mask = genIpv6Mask(cidrRange);
|
|
|
+ const mask = genIpv6Mask(cidrRange);
|
|
|
|
|
|
for (let j = 0; j < 8; j++) {
|
|
|
cidrIp1[j] = network[j] & mask[j];
|
|
|
cidrIp2[j] = cidrIp1[j] | (~mask[j] & 0x0000FFFF);
|
|
|
}
|
|
|
- ipv6List.splice(ipv6List.indexOf(ipv6CidrList[i]),1);
|
|
|
+ ipv6List.splice(ipv6List.indexOf(ipv6CidrList[i]), 1);
|
|
|
ipv6List.push(ipv6ToStr(cidrIp1), ipv6ToStr(cidrIp2));
|
|
|
}
|
|
|
ipv6List = ipv6List.sort(ipv6Compare);
|
|
|
- let ip1 = ipv6List[0];
|
|
|
- let ip2 = ipv6List[ipv6List.length - 1];
|
|
|
- let range = [ip1 + " - " + ip2]
|
|
|
+ const ip1 = ipv6List[0];
|
|
|
+ const ip2 = ipv6List[ipv6List.length - 1];
|
|
|
+ const range = [ip1 + " - " + ip2];
|
|
|
return ipv6HyphenatedRange(range, includeNetworkInfo);
|
|
|
}
|
|
|
|
|
@@ -492,11 +499,11 @@ export function ipv4Compare(a, b) {
|
|
|
*/
|
|
|
export function ipv6Compare(a, b) {
|
|
|
|
|
|
- let a_ = strToIpv6(a),
|
|
|
+ const a_ = strToIpv6(a),
|
|
|
b_ = strToIpv6(b);
|
|
|
|
|
|
for (let i = 0; i < a_.length; i++){
|
|
|
- if (a_[i] != b_[i]){
|
|
|
+ if (a_[i] !== b_[i]){
|
|
|
return a_[i] - b_[i];
|
|
|
}
|
|
|
}
|