Skip to content

Instantly share code, notes, and snippets.

@ValentinH
Created September 11, 2018 14:38
Show Gist options
  • Save ValentinH/24f906740482d3189f8ed2e62d0ad241 to your computer and use it in GitHub Desktop.
Save ValentinH/24f906740482d3189f8ed2e62d0ad241 to your computer and use it in GitHub Desktop.
function decryptBigIpCookie(cookieValue) {
const [ipPart, portPart] = cookieValue.split('.')
const hexIp = parseInt(ipPart, 10)
.toString(16)
.padStart(8, '0')
const ip1 = parseInt(hexIp.toString().substring(6, 8), 16)
const ip2 = parseInt(hexIp.toString().substring(4, 6), 16)
const ip3 = parseInt(hexIp.toString().substring(2, 4), 16)
const ip4 = parseInt(hexIp.toString().substring(0, 2), 16)
const ip = `${ip1}.${ip2}.${ip3}.${ip4}`
const hexPort = parseInt(portPart, 10)
.toString(16)
.padStart(4, '0')
const port1 = hexPort.toString().substring(2, 4)
const port2 = hexPort.toString().substring(0, 2)
const port = parseInt(`${port1}${port2}`, 16)
return {
ip,
port,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment