function getV6Result (IPv6, compareIp) {
if (IPv6 == compareIp) {
return false
}
const ipAddr = IPv6.split(‘/’)
const compareIpAddr = compareIp.split(‘/’)
const compareMask = compareIpAddr[1]
const mask = ipAddr[1]
let ip = ipAddr[0].split(‘:’)
let compareIP = compareIpAddr[0].split(‘:’)
if (ip[ip.length - 1] == ‘’) {
ip[ip.length - 1] = ‘0000’
}
if (compareIP[compareIP.length - 1] == ‘’) {
compareIP[compareIP.length - 1] = ‘0000’
}
function getV6Mask () {
const maskMin = 128 - Math.min(mask, compareMask)
let maxNum = JSBI.subtract(JSBI.BigInt(Math.pow(2, 128)), JSBI.BigInt(1))
const minNum = JSBI.BigInt(maskMin)
return JSBI.leftShift(maxNum, minNum)
}
function getV6Ip (ips = []) {
// let len = ips.length
let offsetBit = 128
const initValue = 0
return ips.reduce((prev, current) => {
offsetBit -= 16
const a = current
const b = offsetBit
let currentValue = JSBI.BigInt(parseInt(a, 16))
let offsetBitValue = JSBI.BigInt(b)
let currentResult = JSBI.leftShift(currentValue, offsetBitValue)
return JSBI.bitwiseOr(prev, currentResult)
}, JSBI.BigInt(initValue))
}
let results = getV6Ip(ip)
let results2 = getV6Ip(compareIP)
const res1 = JSBI.bitwiseAnd(results, getV6Mask())
const res2 = JSBI.bitwiseAnd(results2, getV6Mask())
return JSBI.equal(res1, res2)
}