mirror of
https://github.com/hotomoe/hotomoe
synced 2024-12-14 22:58:14 +09:00
8cab16c824
Fix #9408
15 lines
516 B
TypeScript
15 lines
516 B
TypeScript
import IPCIDR from 'ip-cidr';
|
|
|
|
export function getIpHash(ip: string) {
|
|
try {
|
|
// because a single person may control many IPv6 addresses,
|
|
// only a /64 subnet prefix of any IP will be taken into account.
|
|
// (this means for IPv4 the entire address is used)
|
|
const prefix = IPCIDR.createAddress(ip).mask(64);
|
|
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
|
} catch (e) {
|
|
const prefix = IPCIDR.createAddress(ip.replace(/:[0-9]+$/, '')).mask(64);
|
|
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
|
}
|
|
}
|