feat: add IP-ASN rule

This commit is contained in:
xishang0128
2024-03-12 03:14:25 +08:00
parent 7ad37ca0e3
commit 44d8a14629
15 changed files with 248 additions and 33 deletions

View File

@@ -14,12 +14,21 @@ type geoip2Country struct {
} `maxminddb:"country"`
}
type Reader struct {
type IPReader struct {
*maxminddb.Reader
databaseType
}
func (r Reader) LookupCode(ipAddress net.IP) []string {
type ASNReader struct {
*maxminddb.Reader
}
type ASNResult struct {
AutonomousSystemNumber uint32 `maxminddb:"autonomous_system_number"`
AutonomousSystemOrganization string `maxminddb:"autonomous_system_organization"`
}
func (r IPReader) LookupCode(ipAddress net.IP) []string {
switch r.databaseType {
case typeMaxmind:
var country geoip2Country
@@ -56,3 +65,9 @@ func (r Reader) LookupCode(ipAddress net.IP) []string {
panic(fmt.Sprint("unknown geoip database type:", r.databaseType))
}
}
func (r ASNReader) LookupASN(ip net.IP) ASNResult {
var result ASNResult
r.Lookup(ip, &result)
return result
}