mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-28 12:30:12 +02:00
utils: getIP formatting
This commit is contained in:
parent
a375000ae9
commit
01240b6ca3
@ -114,12 +114,13 @@ export function checkJSONPost(obj) {
|
||||
export function getIP(req) {
|
||||
const strippedIP = req.ip.replace(/^::ffff:/, '');
|
||||
const ip = ipaddr.parse(strippedIP);
|
||||
if (ip.kind() === 'ipv4')
|
||||
if (ip.kind() === 'ipv4') {
|
||||
return strippedIP;
|
||||
}
|
||||
|
||||
const PREFIX = 56;
|
||||
const prefix = 56;
|
||||
const v6Bytes = ip.toByteArray();
|
||||
v6Bytes.fill(0, PREFIX / 8);
|
||||
v6Bytes.fill(0, prefix / 8);
|
||||
|
||||
return ipaddr.fromByteArray(v6Bytes).toString();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user