misc fixes

This commit is contained in:
Aiden McClelland
2025-08-26 12:13:39 -06:00
parent ff686d3c52
commit 9fe9608560
7 changed files with 59 additions and 36 deletions

View File

@@ -31,6 +31,9 @@ export class IpAddress {
throw new Error("invalid ip address")
}
}
static parse(address: string): IpAddress {
return new IpAddress(address)
}
isIpv4(): boolean {
return this.octets.length === 4
}
@@ -49,6 +52,9 @@ export class IpNet extends IpAddress {
super(address)
this.prefix = Number(prefixStr)
}
static parse(ipnet: string): IpNet {
return new IpNet(ipnet)
}
contains(address: string | IpAddress): boolean {
if (typeof address === "string") address = new IpAddress(address)
if (this.octets.length !== address.octets.length) return false
@@ -75,3 +81,5 @@ export const PRIVATE_IPV4_RANGES = [
]
export const IPV6_LINK_LOCAL = new IpNet("fe80::/10")
export const CGNAT = new IpNet("100.64.0.0/10")