mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 22:21:01 +01:00
Made variables non-private, and followed convention for the references to the IP lib.
This commit is contained in:
parent
ea36687205
commit
3ba12ae9ac
@ -10,8 +10,8 @@ import Utils from "../Utils";
|
|||||||
* @param {boolean} allowLargeList
|
* @param {boolean} allowLargeList
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function _ipv4CidrRange(cidr, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
export function ipv4CidrRange(cidr, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
||||||
const network = _strToIpv4(cidr[1]),
|
const network = strToIpv4(cidr[1]),
|
||||||
cidrRange = parseInt(cidr[2], 10);
|
cidrRange = parseInt(cidr[2], 10);
|
||||||
let output = "";
|
let output = "";
|
||||||
|
|
||||||
@ -24,16 +24,16 @@ export function _ipv4CidrRange(cidr, includeNetworkInfo, enumerateAddresses, all
|
|||||||
ip2 = ip1 | ~mask;
|
ip2 = ip1 | ~mask;
|
||||||
|
|
||||||
if (includeNetworkInfo) {
|
if (includeNetworkInfo) {
|
||||||
output += "Network: " + _ipv4ToStr(network) + "\n";
|
output += "Network: " + ipv4ToStr(network) + "\n";
|
||||||
output += "CIDR: " + cidrRange + "\n";
|
output += "CIDR: " + cidrRange + "\n";
|
||||||
output += "Mask: " + _ipv4ToStr(mask) + "\n";
|
output += "Mask: " + ipv4ToStr(mask) + "\n";
|
||||||
output += "Range: " + _ipv4ToStr(ip1) + " - " + _ipv4ToStr(ip2) + "\n";
|
output += "Range: " + ipv4ToStr(ip1) + " - " + ipv4ToStr(ip2) + "\n";
|
||||||
output += "Total addresses in range: " + (((ip2 - ip1) >>> 0) + 1) + "\n\n";
|
output += "Total addresses in range: " + (((ip2 - ip1) >>> 0) + 1) + "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enumerateAddresses) {
|
if (enumerateAddresses) {
|
||||||
if (cidrRange >= 16 || allowLargeList) {
|
if (cidrRange >= 16 || allowLargeList) {
|
||||||
output += _generateIpv4Range(ip1, ip2).join("\n");
|
output += generateIpv4Range(ip1, ip2).join("\n");
|
||||||
} else {
|
} else {
|
||||||
output += _LARGE_RANGE_ERROR;
|
output += _LARGE_RANGE_ERROR;
|
||||||
}
|
}
|
||||||
@ -49,9 +49,9 @@ export function _ipv4CidrRange(cidr, includeNetworkInfo, enumerateAddresses, all
|
|||||||
* @param {boolean} includeNetworkInfo
|
* @param {boolean} includeNetworkInfo
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function _ipv6CidrRange(cidr, includeNetworkInfo) {
|
export function ipv6CidrRange(cidr, includeNetworkInfo) {
|
||||||
let output = "";
|
let output = "";
|
||||||
const network = _strToIpv6(cidr[1]),
|
const network = strToIpv6(cidr[1]),
|
||||||
cidrRange = parseInt(cidr[cidr.length-1], 10);
|
cidrRange = parseInt(cidr[cidr.length-1], 10);
|
||||||
|
|
||||||
if (cidrRange < 0 || cidrRange > 127) {
|
if (cidrRange < 0 || cidrRange > 127) {
|
||||||
@ -62,7 +62,7 @@ export function _ipv6CidrRange(cidr, includeNetworkInfo) {
|
|||||||
ip2 = new Array(8),
|
ip2 = new Array(8),
|
||||||
total = new Array(128);
|
total = new Array(128);
|
||||||
|
|
||||||
const mask = _genIpv6Mask(cidrRange);
|
const mask = genIpv6Mask(cidrRange);
|
||||||
let totalDiff = "";
|
let totalDiff = "";
|
||||||
|
|
||||||
|
|
||||||
@ -79,11 +79,11 @@ export function _ipv6CidrRange(cidr, includeNetworkInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (includeNetworkInfo) {
|
if (includeNetworkInfo) {
|
||||||
output += "Network: " + _ipv6ToStr(network) + "\n";
|
output += "Network: " + ipv6ToStr(network) + "\n";
|
||||||
output += "Shorthand: " + _ipv6ToStr(network, true) + "\n";
|
output += "Shorthand: " + ipv6ToStr(network, true) + "\n";
|
||||||
output += "CIDR: " + cidrRange + "\n";
|
output += "CIDR: " + cidrRange + "\n";
|
||||||
output += "Mask: " + _ipv6ToStr(mask) + "\n";
|
output += "Mask: " + ipv6ToStr(mask) + "\n";
|
||||||
output += "Range: " + _ipv6ToStr(ip1) + " - " + _ipv6ToStr(ip2) + "\n";
|
output += "Range: " + ipv6ToStr(ip1) + " - " + ipv6ToStr(ip2) + "\n";
|
||||||
output += "Total addresses in range: " + (parseInt(total.join(""), 2) + 1) + "\n\n";
|
output += "Total addresses in range: " + (parseInt(total.join(""), 2) + 1) + "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,9 +101,9 @@ export function _ipv6CidrRange(cidr, includeNetworkInfo) {
|
|||||||
* @param {boolean} allowLargeList
|
* @param {boolean} allowLargeList
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function _ipv4HyphenatedRange(range, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
export function ipv4HyphenatedRange(range, includeNetworkInfo, enumerateAddresses, allowLargeList) {
|
||||||
const ip1 = _strToIpv4(range[1]),
|
const ip1 = strToIpv4(range[1]),
|
||||||
ip2 = _strToIpv4(range[2]);
|
ip2 = strToIpv4(range[2]);
|
||||||
|
|
||||||
let output = "";
|
let output = "";
|
||||||
// Calculate mask
|
// Calculate mask
|
||||||
@ -124,18 +124,18 @@ export function _ipv4HyphenatedRange(range, includeNetworkInfo, enumerateAddress
|
|||||||
|
|
||||||
if (includeNetworkInfo) {
|
if (includeNetworkInfo) {
|
||||||
output += "Minimum subnet required to hold this range:\n";
|
output += "Minimum subnet required to hold this range:\n";
|
||||||
output += "\tNetwork: " + _ipv4ToStr(network) + "\n";
|
output += "\tNetwork: " + ipv4ToStr(network) + "\n";
|
||||||
output += "\tCIDR: " + cidr + "\n";
|
output += "\tCIDR: " + cidr + "\n";
|
||||||
output += "\tMask: " + _ipv4ToStr(mask) + "\n";
|
output += "\tMask: " + ipv4ToStr(mask) + "\n";
|
||||||
output += "\tSubnet range: " + _ipv4ToStr(subIp1) + " - " + _ipv4ToStr(subIp2) + "\n";
|
output += "\tSubnet range: " + ipv4ToStr(subIp1) + " - " + ipv4ToStr(subIp2) + "\n";
|
||||||
output += "\tTotal addresses in subnet: " + (((subIp2 - subIp1) >>> 0) + 1) + "\n\n";
|
output += "\tTotal addresses in subnet: " + (((subIp2 - subIp1) >>> 0) + 1) + "\n\n";
|
||||||
output += "Range: " + _ipv4ToStr(ip1) + " - " + _ipv4ToStr(ip2) + "\n";
|
output += "Range: " + ipv4ToStr(ip1) + " - " + ipv4ToStr(ip2) + "\n";
|
||||||
output += "Total addresses in range: " + (((ip2 - ip1) >>> 0) + 1) + "\n\n";
|
output += "Total addresses in range: " + (((ip2 - ip1) >>> 0) + 1) + "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enumerateAddresses) {
|
if (enumerateAddresses) {
|
||||||
if (((ip2 - ip1) >>> 0) <= 65536 || allowLargeList) {
|
if (((ip2 - ip1) >>> 0) <= 65536 || allowLargeList) {
|
||||||
output += _generateIpv4Range(ip1, ip2).join("\n");
|
output += generateIpv4Range(ip1, ip2).join("\n");
|
||||||
} else {
|
} else {
|
||||||
output += _LARGE_RANGE_ERROR;
|
output += _LARGE_RANGE_ERROR;
|
||||||
}
|
}
|
||||||
@ -152,9 +152,9 @@ export function _ipv4HyphenatedRange(range, includeNetworkInfo, enumerateAddress
|
|||||||
* @param {boolean} includeNetworkInfo
|
* @param {boolean} includeNetworkInfo
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function _ipv6HyphenatedRange(range, includeNetworkInfo) {
|
export function ipv6HyphenatedRange(range, includeNetworkInfo) {
|
||||||
const ip1 = _strToIpv6(range[1]),
|
const ip1 = strToIpv6(range[1]),
|
||||||
ip2 = _strToIpv6(range[14]),
|
ip2 = strToIpv6(range[14]),
|
||||||
total = new Array(128).fill();
|
total = new Array(128).fill();
|
||||||
|
|
||||||
let output = "",
|
let output = "",
|
||||||
@ -171,8 +171,8 @@ export function _ipv6HyphenatedRange(range, includeNetworkInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (includeNetworkInfo) {
|
if (includeNetworkInfo) {
|
||||||
output += "Range: " + _ipv6ToStr(ip1) + " - " + _ipv6ToStr(ip2) + "\n";
|
output += "Range: " + ipv6ToStr(ip1) + " - " + ipv6ToStr(ip2) + "\n";
|
||||||
output += "Shorthand range: " + _ipv6ToStr(ip1, true) + " - " + _ipv6ToStr(ip2, true) + "\n";
|
output += "Shorthand range: " + ipv6ToStr(ip1, true) + " - " + ipv6ToStr(ip2, true) + "\n";
|
||||||
output += "Total addresses in range: " + (parseInt(total.join(""), 2) + 1) + "\n\n";
|
output += "Total addresses in range: " + (parseInt(total.join(""), 2) + 1) + "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,9 +188,9 @@ export function _ipv6HyphenatedRange(range, includeNetworkInfo) {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns 168427520
|
* // returns 168427520
|
||||||
* _strToIpv4("10.10.0.0");
|
* strToIpv4("10.10.0.0");
|
||||||
*/
|
*/
|
||||||
export function _strToIpv4(ipStr) {
|
export function strToIpv4(ipStr) {
|
||||||
const blocks = ipStr.split("."),
|
const blocks = ipStr.split("."),
|
||||||
numBlocks = parseBlocks(blocks);
|
numBlocks = parseBlocks(blocks);
|
||||||
let result = 0;
|
let result = 0;
|
||||||
@ -229,9 +229,9 @@ export function _strToIpv4(ipStr) {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns "10.10.0.0"
|
* // returns "10.10.0.0"
|
||||||
* _ipv4ToStr(168427520);
|
* ipv4ToStr(168427520);
|
||||||
*/
|
*/
|
||||||
export function _ipv4ToStr(ipInt) {
|
export function ipv4ToStr(ipInt) {
|
||||||
const blockA = (ipInt >> 24) & 255,
|
const blockA = (ipInt >> 24) & 255,
|
||||||
blockB = (ipInt >> 16) & 255,
|
blockB = (ipInt >> 16) & 255,
|
||||||
blockC = (ipInt >> 8) & 255,
|
blockC = (ipInt >> 8) & 255,
|
||||||
@ -250,9 +250,9 @@ export function _ipv4ToStr(ipInt) {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns [65280, 0, 0, 0, 0, 0, 4369, 8738]
|
* // returns [65280, 0, 0, 0, 0, 0, 4369, 8738]
|
||||||
* _strToIpv6("ff00::1111:2222");
|
* strToIpv6("ff00::1111:2222");
|
||||||
*/
|
*/
|
||||||
export function _strToIpv6(ipStr) {
|
export function strToIpv6(ipStr) {
|
||||||
let j = 0;
|
let j = 0;
|
||||||
const blocks = ipStr.split(":"),
|
const blocks = ipStr.split(":"),
|
||||||
numBlocks = parseBlocks(blocks),
|
numBlocks = parseBlocks(blocks),
|
||||||
@ -296,12 +296,12 @@ export function _strToIpv6(ipStr) {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns "ff00::1111:2222"
|
* // returns "ff00::1111:2222"
|
||||||
* _ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], true);
|
* ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], true);
|
||||||
*
|
*
|
||||||
* // returns "ff00:0000:0000:0000:0000:0000:1111:2222"
|
* // returns "ff00:0000:0000:0000:0000:0000:1111:2222"
|
||||||
* _ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], false);
|
* ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], false);
|
||||||
*/
|
*/
|
||||||
export function _ipv6ToStr(ipv6, compact) {
|
export function ipv6ToStr(ipv6, compact) {
|
||||||
let output = "",
|
let output = "",
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
@ -352,13 +352,13 @@ export function _ipv6ToStr(ipv6, compact) {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns ["0.0.0.1", "0.0.0.2", "0.0.0.3"]
|
* // returns ["0.0.0.1", "0.0.0.2", "0.0.0.3"]
|
||||||
* IP._generateIpv4Range(1, 3);
|
* IP.generateIpv4Range(1, 3);
|
||||||
*/
|
*/
|
||||||
export function _generateIpv4Range(ip, endIp) {
|
export function generateIpv4Range(ip, endIp) {
|
||||||
const range = [];
|
const range = [];
|
||||||
if (endIp >= ip) {
|
if (endIp >= ip) {
|
||||||
for (; ip <= endIp; ip++) {
|
for (; ip <= endIp; ip++) {
|
||||||
range.push(_ipv4ToStr(ip));
|
range.push(ipv4ToStr(ip));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
range[0] = "Second IP address smaller than first.";
|
range[0] = "Second IP address smaller than first.";
|
||||||
@ -373,7 +373,7 @@ export function _generateIpv4Range(ip, endIp) {
|
|||||||
* @param {number} cidr
|
* @param {number} cidr
|
||||||
* @returns {number[]}
|
* @returns {number[]}
|
||||||
*/
|
*/
|
||||||
export function _genIpv6Mask(cidr) {
|
export function genIpv6Mask(cidr) {
|
||||||
const mask = new Array(8);
|
const mask = new Array(8);
|
||||||
let shift;
|
let shift;
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ export const IPV6_REGEX = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|)
|
|||||||
* @private
|
* @private
|
||||||
* @constant
|
* @constant
|
||||||
*/
|
*/
|
||||||
export const _protocolLookup = {
|
export const protocolLookup = {
|
||||||
0: {keyword: "HOPOPT", protocol: "IPv6 Hop-by-Hop Option"},
|
0: {keyword: "HOPOPT", protocol: "IPv6 Hop-by-Hop Option"},
|
||||||
1: {keyword: "ICMP", protocol: "Internet Control Message"},
|
1: {keyword: "ICMP", protocol: "Internet Control Message"},
|
||||||
2: {keyword: "IGMP", protocol: "Internet Group Management"},
|
2: {keyword: "IGMP", protocol: "Internet Group Management"},
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import {fromHex} from "../lib/Hex";
|
import {fromHex} from "../lib/Hex.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change IP format operation
|
* Change IP format operation
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
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
|
* Group IP addresses operation
|
||||||
@ -53,7 +53,7 @@ class GroupIPAddresses extends Operation {
|
|||||||
cidr = args[1],
|
cidr = args[1],
|
||||||
onlySubnets = args[2],
|
onlySubnets = args[2],
|
||||||
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
|
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
|
||||||
ipv6Mask = _genIpv6Mask(cidr),
|
ipv6Mask = genIpv6Mask(cidr),
|
||||||
ips = input.split(delim),
|
ips = input.split(delim),
|
||||||
ipv4Networks = {},
|
ipv4Networks = {},
|
||||||
ipv6Networks = {};
|
ipv6Networks = {};
|
||||||
@ -71,7 +71,7 @@ class GroupIPAddresses extends Operation {
|
|||||||
// Parse all IPs and add to network dictionary
|
// Parse all IPs and add to network dictionary
|
||||||
for (i = 0; i < ips.length; i++) {
|
for (i = 0; i < ips.length; i++) {
|
||||||
if ((match = IPV4_REGEX.exec(ips[i]))) {
|
if ((match = IPV4_REGEX.exec(ips[i]))) {
|
||||||
ip = _strToIpv4(match[1]) >>> 0;
|
ip = strToIpv4(match[1]) >>> 0;
|
||||||
network = ip & ipv4Mask;
|
network = ip & ipv4Mask;
|
||||||
|
|
||||||
if (ipv4Networks.hasOwnProperty(network)) {
|
if (ipv4Networks.hasOwnProperty(network)) {
|
||||||
@ -80,7 +80,7 @@ class GroupIPAddresses extends Operation {
|
|||||||
ipv4Networks[network] = [ip];
|
ipv4Networks[network] = [ip];
|
||||||
}
|
}
|
||||||
} else if ((match = IPV6_REGEX.exec(ips[i]))) {
|
} else if ((match = IPV6_REGEX.exec(ips[i]))) {
|
||||||
ip = _strToIpv6(match[1]);
|
ip = strToIpv6(match[1]);
|
||||||
network = [];
|
network = [];
|
||||||
networkStr = "";
|
networkStr = "";
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ class GroupIPAddresses extends Operation {
|
|||||||
network.push(ip[j] & ipv6Mask[j]);
|
network.push(ip[j] & ipv6Mask[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
networkStr = _ipv6ToStr(network, true);
|
networkStr = ipv6ToStr(network, true);
|
||||||
|
|
||||||
if (ipv6Networks.hasOwnProperty(networkStr)) {
|
if (ipv6Networks.hasOwnProperty(networkStr)) {
|
||||||
ipv6Networks[networkStr].push(ip);
|
ipv6Networks[networkStr].push(ip);
|
||||||
@ -102,11 +102,11 @@ class GroupIPAddresses extends Operation {
|
|||||||
for (network in ipv4Networks) {
|
for (network in ipv4Networks) {
|
||||||
ipv4Networks[network] = ipv4Networks[network].sort();
|
ipv4Networks[network] = ipv4Networks[network].sort();
|
||||||
|
|
||||||
output += _ipv4ToStr(network) + "/" + cidr + "\n";
|
output += ipv4ToStr(network) + "/" + cidr + "\n";
|
||||||
|
|
||||||
if (!onlySubnets) {
|
if (!onlySubnets) {
|
||||||
for (i = 0; i < ipv4Networks[network].length; i++) {
|
for (i = 0; i < ipv4Networks[network].length; i++) {
|
||||||
output += " " + _ipv4ToStr(ipv4Networks[network][i]) + "\n";
|
output += " " + ipv4ToStr(ipv4Networks[network][i]) + "\n";
|
||||||
}
|
}
|
||||||
output += "\n";
|
output += "\n";
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ class GroupIPAddresses extends Operation {
|
|||||||
|
|
||||||
if (!onlySubnets) {
|
if (!onlySubnets) {
|
||||||
for (i = 0; i < ipv6Networks[networkStr].length; i++) {
|
for (i = 0; i < ipv6Networks[networkStr].length; i++) {
|
||||||
output += " " + _ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
|
output += " " + ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
|
||||||
}
|
}
|
||||||
output += "\n";
|
output += "\n";
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import {_ipv4CidrRange, _ipv4HyphenatedRange, _ipv6CidrRange, _ipv6HyphenatedRange} from "../lib/Ip";
|
import {ipv4CidrRange, ipv4HyphenatedRange, ipv6CidrRange, ipv6HyphenatedRange} from "../lib/Ip";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse IP range operation
|
* Parse IP range operation
|
||||||
@ -60,13 +60,13 @@ class ParseIPRange extends Operation {
|
|||||||
let match;
|
let match;
|
||||||
|
|
||||||
if ((match = ipv4CidrRegex.exec(input))) {
|
if ((match = ipv4CidrRegex.exec(input))) {
|
||||||
return _ipv4CidrRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
return ipv4CidrRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
||||||
} else if ((match = ipv4RangeRegex.exec(input))) {
|
} else if ((match = ipv4RangeRegex.exec(input))) {
|
||||||
return _ipv4HyphenatedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
return ipv4HyphenatedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
||||||
} else if ((match = ipv6CidrRegex.exec(input))) {
|
} else if ((match = ipv6CidrRegex.exec(input))) {
|
||||||
return _ipv6CidrRange(match, includeNetworkInfo);
|
return ipv6CidrRange(match, includeNetworkInfo);
|
||||||
} else if ((match = ipv6RangeRegex.exec(input))) {
|
} else if ((match = ipv6RangeRegex.exec(input))) {
|
||||||
return _ipv6HyphenatedRange(match, includeNetworkInfo);
|
return ipv6HyphenatedRange(match, includeNetworkInfo);
|
||||||
} else {
|
} else {
|
||||||
return "Invalid input.\n\nEnter either a CIDR range (e.g. 10.0.0.0/24) or a hyphenated range (e.g. 10.0.0.0 - 10.0.1.0). IPv6 also supported.";
|
return "Invalid input.\n\nEnter either a CIDR range (e.g. 10.0.0.0/24) or a hyphenated range (e.g. 10.0.0.0 - 10.0.1.0). IPv6 also supported.";
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import {fromHex, toHex} from "../lib/Hex";
|
import {fromHex, toHex} from "../lib/Hex.mjs";
|
||||||
import {_ipv4ToStr, _protocolLookup, calculateTCPIPChecksum} from "../lib/Ip";
|
import {ipv4ToStr, protocolLookup, calculateTCPIPChecksum} from "../lib/Ip.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse IPv4 header operation
|
* Parse IPv4 header operation
|
||||||
@ -83,7 +83,7 @@ class ParseIPv4Header extends Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Protocol
|
// Protocol
|
||||||
const protocolInfo = _protocolLookup[protocol] || {keyword: "", protocol: ""};
|
const protocolInfo = protocolLookup[protocol] || {keyword: "", protocol: ""};
|
||||||
|
|
||||||
// Checksum
|
// Checksum
|
||||||
const correctChecksum = calculateTCPIPChecksum(checksumHeader),
|
const correctChecksum = calculateTCPIPChecksum(checksumHeader),
|
||||||
@ -112,8 +112,8 @@ class ParseIPv4Header extends Operation {
|
|||||||
"<tr><td>Time-To-Live</td><td>" + ttl + "</td></tr>" +
|
"<tr><td>Time-To-Live</td><td>" + ttl + "</td></tr>" +
|
||||||
"<tr><td>Protocol</td><td>" + protocol + ", " + protocolInfo.protocol + " (" + protocolInfo.keyword + ")</td></tr>" +
|
"<tr><td>Protocol</td><td>" + protocol + ", " + protocolInfo.protocol + " (" + protocolInfo.keyword + ")</td></tr>" +
|
||||||
"<tr><td>Header checksum</td><td>" + checksumResult + "</td></tr>" +
|
"<tr><td>Header checksum</td><td>" + checksumResult + "</td></tr>" +
|
||||||
"<tr><td>Source IP address</td><td>" + _ipv4ToStr(srcIP) + "</td></tr>" +
|
"<tr><td>Source IP address</td><td>" + ipv4ToStr(srcIP) + "</td></tr>" +
|
||||||
"<tr><td>Destination IP address</td><td>" + _ipv4ToStr(dstIP) + "</td></tr>";
|
"<tr><td>Destination IP address</td><td>" + ipv4ToStr(dstIP) + "</td></tr>";
|
||||||
|
|
||||||
if (ihl > 5) {
|
if (ihl > 5) {
|
||||||
output += "<tr><td>Options</td><td>" + toHex(options) + "</td></tr>";
|
output += "<tr><td>Options</td><td>" + toHex(options) + "</td></tr>";
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import {_strToIpv6, _ipv6ToStr, _ipv4ToStr, IPV6_REGEX} from "../lib/Ip";
|
import {strToIpv6, ipv6ToStr, ipv4ToStr, IPV6_REGEX} from "../lib/Ip.mjs";
|
||||||
import BigInteger from "jsbn";
|
import BigInteger from "jsbn";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,9 +38,9 @@ class ParseIPv6Address extends Operation {
|
|||||||
output = "";
|
output = "";
|
||||||
|
|
||||||
if ((match = IPV6_REGEX.exec(input))) {
|
if ((match = IPV6_REGEX.exec(input))) {
|
||||||
const ipv6 = _strToIpv6(match[1]),
|
const ipv6 = strToIpv6(match[1]),
|
||||||
longhand = _ipv6ToStr(ipv6),
|
longhand = ipv6ToStr(ipv6),
|
||||||
shorthand = _ipv6ToStr(ipv6, true);
|
shorthand = ipv6ToStr(ipv6, true);
|
||||||
|
|
||||||
output += "Longhand: " + longhand + "\nShorthand: " + shorthand + "\n";
|
output += "Longhand: " + longhand + "\nShorthand: " + shorthand + "\n";
|
||||||
|
|
||||||
@ -57,13 +57,13 @@ class ParseIPv6Address extends Operation {
|
|||||||
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0xffff) {
|
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0xffff) {
|
||||||
// IPv4-mapped IPv6 address
|
// IPv4-mapped IPv6 address
|
||||||
output += "\nIPv4-mapped IPv6 address detected. IPv6 clients will be handled natively by default, and IPv4 clients appear as IPv6 clients at their IPv4-mapped IPv6 address.";
|
output += "\nIPv4-mapped IPv6 address detected. IPv6 clients will be handled natively by default, and IPv4 clients appear as IPv6 clients at their IPv4-mapped IPv6 address.";
|
||||||
output += "\nMapped IPv4 address: " + _ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
output += "\nMapped IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||||
output += "\nIPv4-mapped IPv6 addresses range: ::ffff:0:0/96";
|
output += "\nIPv4-mapped IPv6 addresses range: ::ffff:0:0/96";
|
||||||
} else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 &&
|
} else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 &&
|
||||||
ipv6[3] === 0 && ipv6[4] === 0xffff && ipv6[5] === 0) {
|
ipv6[3] === 0 && ipv6[4] === 0xffff && ipv6[5] === 0) {
|
||||||
// IPv4-translated address
|
// IPv4-translated address
|
||||||
output += "\nIPv4-translated address detected. Used by Stateless IP/ICMP Translation (SIIT). See RFCs 6145 and 6052 for more details.";
|
output += "\nIPv4-translated address detected. Used by Stateless IP/ICMP Translation (SIIT). See RFCs 6145 and 6052 for more details.";
|
||||||
output += "\nTranslated IPv4 address: " + _ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||||
output += "\nIPv4-translated addresses range: ::ffff:0:0:0/96";
|
output += "\nIPv4-translated addresses range: ::ffff:0:0:0/96";
|
||||||
} else if (ipv6[0] === 0x100) {
|
} else if (ipv6[0] === 0x100) {
|
||||||
// Discard prefix per RFC 6666
|
// Discard prefix per RFC 6666
|
||||||
@ -73,7 +73,7 @@ class ParseIPv6Address extends Operation {
|
|||||||
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0) {
|
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0) {
|
||||||
// IPv4/IPv6 translation per RFC 6052
|
// IPv4/IPv6 translation per RFC 6052
|
||||||
output += "\n'Well-Known' prefix for IPv4/IPv6 translation detected. See RFC 6052 for more details.";
|
output += "\n'Well-Known' prefix for IPv4/IPv6 translation detected. See RFC 6052 for more details.";
|
||||||
output += "\nTranslated IPv4 address: " + _ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||||
output += "\n'Well-Known' prefix range: 64:ff9b::/96";
|
output += "\n'Well-Known' prefix range: 64:ff9b::/96";
|
||||||
} else if (ipv6[0] === 0x2001 && ipv6[1] === 0) {
|
} else if (ipv6[0] === 0x2001 && ipv6[1] === 0) {
|
||||||
// Teredo tunneling
|
// Teredo tunneling
|
||||||
@ -87,8 +87,8 @@ class ParseIPv6Address extends Operation {
|
|||||||
flagUg = (ipv6[4] >>> 8) & 3,
|
flagUg = (ipv6[4] >>> 8) & 3,
|
||||||
flagRandom2 = ipv6[4] & 255;
|
flagRandom2 = ipv6[4] & 255;
|
||||||
|
|
||||||
output += "\nServer IPv4 address: " + _ipv4ToStr(serverIpv4) +
|
output += "\nServer IPv4 address: " + ipv4ToStr(serverIpv4) +
|
||||||
"\nClient IPv4 address: " + _ipv4ToStr(clientIpv4) +
|
"\nClient IPv4 address: " + ipv4ToStr(clientIpv4) +
|
||||||
"\nClient UDP port: " + udpPort +
|
"\nClient UDP port: " + udpPort +
|
||||||
"\nFlags:" +
|
"\nFlags:" +
|
||||||
"\n\tCone: " + flagCone;
|
"\n\tCone: " + flagCone;
|
||||||
@ -142,7 +142,7 @@ class ParseIPv6Address extends Operation {
|
|||||||
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";
|
||||||
|
|
||||||
const v4Addr = _ipv4ToStr((ipv6[1] << 16) + ipv6[2]),
|
const v4Addr = 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);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import {calculateTCPIPChecksum} from "../lib/Ip";
|
import {calculateTCPIPChecksum} from "../lib/Ip.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCP/IP Checksum operation
|
* TCP/IP Checksum operation
|
||||||
|
Loading…
Reference in New Issue
Block a user