From 0941d8bbb8950f195d910546726fb1d975839385 Mon Sep 17 00:00:00 2001 From: leicheng Date: Fri, 6 Jul 2018 16:08:14 +0800 Subject: [PATCH] cidr rule use ip of domain name. --- rule.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rule.go b/rule.go index f45e237..40efdbf 100644 --- a/rule.go +++ b/rule.go @@ -70,7 +70,18 @@ func (rd *RuleDialer) NextDialer(dstAddr string) proxy.Dialer { } // find ip - if ip := net.ParseIP(host); ip != nil { + ip := net.ParseIP(host) + if ip == nil { + ns, err := net.LookupHost(host) + if err == nil { + if (len(ns) > 0) { + ip = net.ParseIP(ns[0]) + } + } else { + log.F("[rule] Invalid host: %s", host) + } + } + if ip != nil { // check ip if dialer, ok := rd.ipMap.Load(ip.String()); ok { return dialer.(proxy.Dialer)