mirror of
https://github.com/wukko/cobalt.git
synced 2025-01-12 20:25:06 +01:00
utils: getIP formatting
This commit is contained in:
parent
a375000ae9
commit
01240b6ca3
1 changed files with 4 additions and 3 deletions
|
@ -114,12 +114,13 @@ export function checkJSONPost(obj) {
|
||||||
export function getIP(req) {
|
export function getIP(req) {
|
||||||
const strippedIP = req.ip.replace(/^::ffff:/, '');
|
const strippedIP = req.ip.replace(/^::ffff:/, '');
|
||||||
const ip = ipaddr.parse(strippedIP);
|
const ip = ipaddr.parse(strippedIP);
|
||||||
if (ip.kind() === 'ipv4')
|
if (ip.kind() === 'ipv4') {
|
||||||
return strippedIP;
|
return strippedIP;
|
||||||
|
}
|
||||||
|
|
||||||
const PREFIX = 56;
|
const prefix = 56;
|
||||||
const v6Bytes = ip.toByteArray();
|
const v6Bytes = ip.toByteArray();
|
||||||
v6Bytes.fill(0, PREFIX / 8);
|
v6Bytes.fill(0, prefix / 8);
|
||||||
|
|
||||||
return ipaddr.fromByteArray(v6Bytes).toString();
|
return ipaddr.fromByteArray(v6Bytes).toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue