diff --git a/check.go b/check.go index c1c5e94..ff13b87 100644 --- a/check.go +++ b/check.go @@ -8,15 +8,9 @@ func isCloudflare(ip net.IP) bool { continue } - hosts, err := hosts(c) - if err != nil { - continue - } - - for _, host := range hosts { - if host == ip.String() { - return true - } + _, cidrNet, _ := net.ParseCIDR(c) + if cidrNet.Contains(ip) { + return true } } return false diff --git a/utils.go b/utils.go index cb646a4..4d803af 100644 --- a/utils.go +++ b/utils.go @@ -14,35 +14,6 @@ func show(host string, ip net.IP, mode bool) { } } -func inc(ip net.IP) { - for j := len(ip) - 1; j >= 0; j-- { - ip[j]++ - if ip[j] > 0 { - break - } - } -} - -func hosts(cidr string) ([]string, error) { - ip, ipnet, err := net.ParseCIDR(cidr) - if err != nil { - return nil, err - } - - var ips []string - for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) { - ips = append(ips, ip.String()) - } - - lenIPs := len(ips) - switch { - case lenIPs < 2: - return ips, nil - default: - return ips[1 : len(ips)-1], nil - } -} - func isStdin() bool { f, e := os.Stdin.Stat() if e != nil {