From 49f16670df4aa07526c5ba4442120ef87e9a2e6e Mon Sep 17 00:00:00 2001 From: vladimir-plokhotnichenko <50494541+vladimir-plokhotnichenko@users.noreply.github.com> Date: Sun, 12 May 2024 17:32:18 +0300 Subject: [PATCH 1/5] Fixed .0 addresses Fixed .0 addresses (such as 188.114.96.0) being not detected as part of subnet --- check.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/check.go b/check.go index c1c5e94..6b516b5 100644 --- a/check.go +++ b/check.go @@ -3,21 +3,15 @@ package main import "net" func isCloudflare(ip net.IP) bool { - for _, c := range cidrs { - if c == "" { - continue - } + for _, c := range cidrs { + if c == "" { + continue + } - hosts, err := hosts(c) - if err != nil { - continue - } - - for _, host := range hosts { - if host == ip.String() { - return true - } - } - } - return false + _, cidrNet, _ := net.ParseCIDR(c) + if cidrNet.Contains(ip) { + return true + } + } + return false } From 2a7e61f6416e4d48b34d13c5c0d784849d0ededa Mon Sep 17 00:00:00 2001 From: vladimir-plokhotnichenko <50494541+vladimir-plokhotnichenko@users.noreply.github.com> Date: Sun, 12 May 2024 17:32:59 +0300 Subject: [PATCH 2/5] Update prefixes.txt taken from https://www.cloudflare.com/ips-v4 --- db/prefixes.txt | 164 +++--------------------------------------------- 1 file changed, 8 insertions(+), 156 deletions(-) diff --git a/db/prefixes.txt b/db/prefixes.txt index da72d60..eb8553f 100644 --- a/db/prefixes.txt +++ b/db/prefixes.txt @@ -1,163 +1,15 @@ -1.0.0.0/24 -1.0.128.0/17 -1.1.1.0/24 -1.1.128.0/17 -1.12.0.0/14 -1.22.0.0/15 -1.38.0.0/15 -1.4.128.0/17 -1.52.0.0/14 -1.66.0.0/15 -103.204.180.0/22 -103.209.140.0/22 +173.245.48.0/20 103.21.244.0/22 -103.212.224.0/22 -103.217.92.0/22 -103.219.164.0/22 103.22.200.0/22 -103.220.16.0/22 -103.229.84.0/22 -103.230.64.0/22 -103.240.136.0/22 -103.243.20.0/22 -103.243.96.0/22 -103.248.80.0/22 -103.249.236.0/22 -103.250.136.0/22 -103.251.216.0/22 -103.253.108.0/22 103.31.4.0/22 -103.81.228.0/24 -104.153.196.0/22 -104.16.0.0/12 -104.171.160.0/20 -104.192.32.0/21 -104.200.128.0/19 -104.200.96.0/20 -104.201.64.0/18 -104.204.0.0/16 -104.247.32.0/19 -104.37.192.0/21 -104.64.0.0/10 -105.112.0.0/12 -105.128.0.0/11 -105.184.0.0/14 -105.228.0.0/15 -106.75.0.0/16 -106.96.0.0/13 -107.172.0.0/14 -108.162.192.0/18 -109.76.0.0/14 -109.86.0.0/15 -110.174.0.0/15 -110.36.0.0/14 -12.0.0.0/8 -13.104.0.0/14 -139.28.216.0/22 -139.38.0.0/16 -139.61.0.0/16 -14.0.128.0/17 -14.32.0.0/11 141.101.64.0/18 -141.226.184.0/21 -142.167.0.0/16 -142.229.0.0/16 -160.131.0.0/16 -160.154.0.0/15 -161.213.0.0/16 -161.215.0.0/16 -161.217.0.0/16 -161.239.0.0/16 -161.8.0.0/16 -162.158.0.0/15 -162.208.96.0/22 -162.210.96.0/21 -162.212.24.0/21 -162.213.16.0/22 -162.213.188.0/22 -162.216.44.0/22 -162.217.248.0/22 -162.247.240.0/22 -162.249.240.0/21 -162.251.80.0/22 -162.41.0.0/16 -162.93.0.0/16 -163.171.192.0/18 -164.115.0.0/16 -164.240.0.0/12 -165.166.0.0/16 -165.227.0.0/16 -165.84.128.0/18 -166.21.0.0/16 -166.95.0.0/16 -171.224.0.0/11 -172.111.128.0/17 -172.242.0.0/15 -172.64.0.0/13 -172.83.152.0/21 -172.93.128.0/17 -172.94.0.0/17 -172.96.160.0/23 -173.16.0.0/12 -173.180.0.0/14 -173.195.64.0/20 -173.211.0.0/17 -173.215.0.0/17 -173.222.0.0/15 -173.245.48.0/20 -173.45.0.0/18 -173.47.0.0/16 -174.124.0.0/15 -174.192.0.0/10 -175.100.0.0/17 -175.101.0.0/16 -175.176.0.0/17 -175.180.0.0/14 -176.118.112.0/20 -176.122.128.0/18 -176.123.192.0/20 -176.212.0.0/14 -176.232.0.0/15 -176.28.128.0/17 -176.29.0.0/16 -176.33.0.0/16 -176.47.0.0/16 -176.54.0.0/15 -176.56.0.0/19 -176.57.248.0/21 -176.62.0.0/19 -176.62.176.0/20 -176.65.96.0/19 -185.146.172.0/22 -188.114.96.0/20 -189.240.0.0/12 -190.40.0.0/17 +108.162.192.0/18 190.93.240.0/20 -195.242.122.0/23 -196.176.0.0/14 -197.136.0.0/14 -197.160.0.0/13 +188.114.96.0/20 197.234.240.0/22 -198.217.250.0/23 198.41.128.0/17 -198.61.96.0/19 -199.27.128.0/21 -2.176.0.0/12 -2.92.0.0/14 -200.75.160.0/20 -23.227.32.0/19 -5.101.112.0/20 -5.16.0.0/14 -5.252.236.0/22 -5.254.0.0/17 -5.254.160.0/21 -5.53.128.0/17 -5.8.16.0/21 -6.0.0.0/8 -64.68.192.0/20 -65.110.56.0/21 -66.235.200.0/24 -68.67.64.0/20 -8.0.0.0/9 -8.244.0.0/14 -91.234.214.0/24 +162.158.0.0/15 +104.16.0.0/13 +104.24.0.0/14 +172.64.0.0/13 +131.0.72.0/22 From 14724d41d95ee1c77976768bd16062a2baa20fb7 Mon Sep 17 00:00:00 2001 From: vladimir-plokhotnichenko <50494541+vladimir-plokhotnichenko@users.noreply.github.com> Date: Sun, 12 May 2024 17:47:48 +0300 Subject: [PATCH 3/5] revert Update prefixes.txt --- db/prefixes.txt | 164 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 156 insertions(+), 8 deletions(-) diff --git a/db/prefixes.txt b/db/prefixes.txt index eb8553f..da72d60 100644 --- a/db/prefixes.txt +++ b/db/prefixes.txt @@ -1,15 +1,163 @@ -173.245.48.0/20 +1.0.0.0/24 +1.0.128.0/17 +1.1.1.0/24 +1.1.128.0/17 +1.12.0.0/14 +1.22.0.0/15 +1.38.0.0/15 +1.4.128.0/17 +1.52.0.0/14 +1.66.0.0/15 +103.204.180.0/22 +103.209.140.0/22 103.21.244.0/22 +103.212.224.0/22 +103.217.92.0/22 +103.219.164.0/22 103.22.200.0/22 +103.220.16.0/22 +103.229.84.0/22 +103.230.64.0/22 +103.240.136.0/22 +103.243.20.0/22 +103.243.96.0/22 +103.248.80.0/22 +103.249.236.0/22 +103.250.136.0/22 +103.251.216.0/22 +103.253.108.0/22 103.31.4.0/22 -141.101.64.0/18 +103.81.228.0/24 +104.153.196.0/22 +104.16.0.0/12 +104.171.160.0/20 +104.192.32.0/21 +104.200.128.0/19 +104.200.96.0/20 +104.201.64.0/18 +104.204.0.0/16 +104.247.32.0/19 +104.37.192.0/21 +104.64.0.0/10 +105.112.0.0/12 +105.128.0.0/11 +105.184.0.0/14 +105.228.0.0/15 +106.75.0.0/16 +106.96.0.0/13 +107.172.0.0/14 108.162.192.0/18 -190.93.240.0/20 +109.76.0.0/14 +109.86.0.0/15 +110.174.0.0/15 +110.36.0.0/14 +12.0.0.0/8 +13.104.0.0/14 +139.28.216.0/22 +139.38.0.0/16 +139.61.0.0/16 +14.0.128.0/17 +14.32.0.0/11 +141.101.64.0/18 +141.226.184.0/21 +142.167.0.0/16 +142.229.0.0/16 +160.131.0.0/16 +160.154.0.0/15 +161.213.0.0/16 +161.215.0.0/16 +161.217.0.0/16 +161.239.0.0/16 +161.8.0.0/16 +162.158.0.0/15 +162.208.96.0/22 +162.210.96.0/21 +162.212.24.0/21 +162.213.16.0/22 +162.213.188.0/22 +162.216.44.0/22 +162.217.248.0/22 +162.247.240.0/22 +162.249.240.0/21 +162.251.80.0/22 +162.41.0.0/16 +162.93.0.0/16 +163.171.192.0/18 +164.115.0.0/16 +164.240.0.0/12 +165.166.0.0/16 +165.227.0.0/16 +165.84.128.0/18 +166.21.0.0/16 +166.95.0.0/16 +171.224.0.0/11 +172.111.128.0/17 +172.242.0.0/15 +172.64.0.0/13 +172.83.152.0/21 +172.93.128.0/17 +172.94.0.0/17 +172.96.160.0/23 +173.16.0.0/12 +173.180.0.0/14 +173.195.64.0/20 +173.211.0.0/17 +173.215.0.0/17 +173.222.0.0/15 +173.245.48.0/20 +173.45.0.0/18 +173.47.0.0/16 +174.124.0.0/15 +174.192.0.0/10 +175.100.0.0/17 +175.101.0.0/16 +175.176.0.0/17 +175.180.0.0/14 +176.118.112.0/20 +176.122.128.0/18 +176.123.192.0/20 +176.212.0.0/14 +176.232.0.0/15 +176.28.128.0/17 +176.29.0.0/16 +176.33.0.0/16 +176.47.0.0/16 +176.54.0.0/15 +176.56.0.0/19 +176.57.248.0/21 +176.62.0.0/19 +176.62.176.0/20 +176.65.96.0/19 +185.146.172.0/22 188.114.96.0/20 +189.240.0.0/12 +190.40.0.0/17 +190.93.240.0/20 +195.242.122.0/23 +196.176.0.0/14 +197.136.0.0/14 +197.160.0.0/13 197.234.240.0/22 +198.217.250.0/23 198.41.128.0/17 -162.158.0.0/15 -104.16.0.0/13 -104.24.0.0/14 -172.64.0.0/13 -131.0.72.0/22 +198.61.96.0/19 +199.27.128.0/21 +2.176.0.0/12 +2.92.0.0/14 +200.75.160.0/20 +23.227.32.0/19 +5.101.112.0/20 +5.16.0.0/14 +5.252.236.0/22 +5.254.0.0/17 +5.254.160.0/21 +5.53.128.0/17 +5.8.16.0/21 +6.0.0.0/8 +64.68.192.0/20 +65.110.56.0/21 +66.235.200.0/24 +68.67.64.0/20 +8.0.0.0/9 +8.244.0.0/14 +91.234.214.0/24 From b1ebaf8839455f196518d930c522a41124126f7e Mon Sep 17 00:00:00 2001 From: vladimir-plokhotnichenko <50494541+vladimir-plokhotnichenko@users.noreply.github.com> Date: Sun, 12 May 2024 17:55:08 +0300 Subject: [PATCH 4/5] removed unused code --- utils.go | 29 ----------------------------- 1 file changed, 29 deletions(-) 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 { From 821b1a46b4fd2231556ebc05ae9a8506a0cc6589 Mon Sep 17 00:00:00 2001 From: vladimir-plokhotnichenko <50494541+vladimir-plokhotnichenko@users.noreply.github.com> Date: Sun, 12 May 2024 17:55:54 +0300 Subject: [PATCH 5/5] applied go fmt to check.go --- check.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/check.go b/check.go index 6b516b5..ff13b87 100644 --- a/check.go +++ b/check.go @@ -3,15 +3,15 @@ package main import "net" func isCloudflare(ip net.IP) bool { - for _, c := range cidrs { - if c == "" { - continue - } + for _, c := range cidrs { + if c == "" { + continue + } - _, cidrNet, _ := net.ParseCIDR(c) - if cidrNet.Contains(ip) { - return true - } - } - return false + _, cidrNet, _ := net.ParseCIDR(c) + if cidrNet.Contains(ip) { + return true + } + } + return false }