hippofish/packages/backend/src/misc/get-ip-hash.ts

10 lines
357 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import IPCIDR from "ip-cidr";
export function getIpHash(ip: string) {
// 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);
2023-01-13 05:40:33 +01:00
return `ip-${BigInt(`0b${prefix}`).toString(36)}`;
}