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