2020-11-09 10:45:44 +08:00
|
|
|
package iplibrary
|
|
|
|
|
|
|
|
|
|
import "github.com/TeaOSLab/EdgeNode/internal/utils"
|
|
|
|
|
|
2021-01-03 20:18:47 +08:00
|
|
|
// IP条目
|
2020-11-09 10:45:44 +08:00
|
|
|
type IPItem struct {
|
|
|
|
|
Id int64
|
|
|
|
|
IPFrom uint32
|
|
|
|
|
IPTo uint32
|
|
|
|
|
ExpiredAt int64
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 20:18:47 +08:00
|
|
|
// 检查是否包含某个IP
|
2020-11-09 10:45:44 +08:00
|
|
|
func (this *IPItem) Contains(ip uint32) bool {
|
|
|
|
|
if this.IPTo == 0 {
|
|
|
|
|
if this.IPFrom != ip {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if this.IPFrom > ip || this.IPTo < ip {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if this.ExpiredAt > 0 && this.ExpiredAt < utils.UnixTime() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|