2022-08-13 23:55:59 +08:00
|
|
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
|
|
|
|
|
|
|
|
package iplibrary
|
|
|
|
|
|
2022-08-21 23:09:25 +08:00
|
|
|
import (
|
2022-08-22 08:31:53 +08:00
|
|
|
"github.com/iwind/TeaGo/types"
|
2022-08-21 23:09:25 +08:00
|
|
|
)
|
|
|
|
|
|
2024-04-06 09:12:17 +08:00
|
|
|
type ipv4ItemV1 struct {
|
2023-03-30 20:02:46 +08:00
|
|
|
IPFrom uint32
|
|
|
|
|
IPTo uint32
|
|
|
|
|
|
|
|
|
|
Region *ipRegion
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-06 09:12:17 +08:00
|
|
|
type ipv6ItemV1 struct {
|
2022-08-22 08:31:53 +08:00
|
|
|
IPFrom uint64
|
|
|
|
|
IPTo uint64
|
|
|
|
|
|
|
|
|
|
Region *ipRegion
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-06 09:12:17 +08:00
|
|
|
type ipv4ItemV2 struct {
|
|
|
|
|
IPFrom [4]byte
|
|
|
|
|
IPTo [4]byte
|
|
|
|
|
|
|
|
|
|
Region *ipRegion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ipv6ItemV2 struct {
|
|
|
|
|
IPFrom [16]byte
|
|
|
|
|
IPTo [16]byte
|
|
|
|
|
|
|
|
|
|
Region *ipRegion
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-22 08:31:53 +08:00
|
|
|
type ipRegion struct {
|
2023-03-30 20:02:46 +08:00
|
|
|
CountryId uint16
|
|
|
|
|
ProvinceId uint16
|
2022-08-21 23:09:25 +08:00
|
|
|
CityId uint32
|
|
|
|
|
TownId uint32
|
2023-03-30 20:02:46 +08:00
|
|
|
ProviderId uint16
|
2022-08-13 23:55:59 +08:00
|
|
|
}
|
2022-08-22 08:31:53 +08:00
|
|
|
|
2023-03-30 20:02:46 +08:00
|
|
|
func HashRegion(countryId uint16, provinceId uint16, cityId uint32, townId uint32, providerId uint16) string {
|
2022-08-22 08:31:53 +08:00
|
|
|
var providerHash = ""
|
|
|
|
|
if providerId > 0 {
|
|
|
|
|
providerHash = "_" + types.String(providerId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if townId > 0 {
|
|
|
|
|
return "t" + types.String(townId) + providerHash
|
|
|
|
|
}
|
|
|
|
|
if cityId > 0 {
|
|
|
|
|
return "c" + types.String(cityId) + providerHash
|
|
|
|
|
}
|
|
|
|
|
if provinceId > 0 {
|
|
|
|
|
return "p" + types.String(provinceId) + providerHash
|
|
|
|
|
}
|
|
|
|
|
return "a" + types.String(countryId) + providerHash
|
|
|
|
|
}
|