clash/dns/filters.go

27 lines
451 B
Go
Raw Normal View History

2019-09-15 05:36:45 +00:00
package dns
2020-01-11 13:07:01 +00:00
import (
"net"
"github.com/Dreamacro/clash/component/mmdb"
)
2019-09-15 05:36:45 +00:00
type fallbackFilter interface {
Match(net.IP) bool
}
type geoipFilter struct{}
func (gf *geoipFilter) Match(ip net.IP) bool {
2020-01-11 13:07:01 +00:00
record, _ := mmdb.Instance().Country(ip)
2020-03-12 16:11:54 +00:00
return record.Country.IsoCode != "CN" && record.Country.IsoCode != ""
2019-09-15 05:36:45 +00:00
}
type ipnetFilter struct {
ipnet *net.IPNet
}
func (inf *ipnetFilter) Match(ip net.IP) bool {
return inf.ipnet.Contains(ip)
}