mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
Added BigInt return to strToIpv6()
This shouldn't change the outcome of any existing calls to strToIpv6 as the additional parameter is defaulted to not have any effect.
This commit is contained in:
parent
ae1b12c120
commit
8ae5fd084c
1 changed files with 14 additions and 3 deletions
|
@ -336,16 +336,27 @@ export function ipv4ToStr(ipInt) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an IPv6 address from string format to numerical array format.
|
* Converts an IPv6 address from string format to numerical format.
|
||||||
*
|
*
|
||||||
* @param {string} ipStr
|
* @param {string} ipStr
|
||||||
* @returns {number[]}
|
* @param {boolean} retArr If true, an array is returned. If false, a BigInt is returned.
|
||||||
|
* @returns {(number[]|BigInt)}
|
||||||
*
|
*
|
||||||
* @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");
|
||||||
|
*
|
||||||
|
* // returns 126946n
|
||||||
|
* strToIpv6("1:f000", false);
|
||||||
*/
|
*/
|
||||||
export function strToIpv6(ipStr) {
|
export function strToIpv6(ipStr, retArr=true) {
|
||||||
|
if (retArr === false) {
|
||||||
|
if (ipStr.length % 2 === 1) {
|
||||||
|
ipStr = "0" + ipStr;
|
||||||
|
}
|
||||||
|
return BigInt("0x" + ipStr.replace(":", ""));
|
||||||
|
return
|
||||||
|
}
|
||||||
let j = 0;
|
let j = 0;
|
||||||
const blocks = ipStr.split(":"),
|
const blocks = ipStr.split(":"),
|
||||||
numBlocks = parseBlocks(blocks),
|
numBlocks = parseBlocks(blocks),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue