├── .github ├── FUNDING.yml ├── scripts │ └── update.sh └── workflows │ ├── build.yaml │ ├── release.yaml │ └── update.yaml ├── .gitignore ├── .goreleaser.yml ├── LICENSE ├── README.md ├── check.go ├── db ├── db.go ├── prefixes.txt └── vars.go ├── go.mod ├── main.go ├── utils.go └── vars.go /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ["dwisiswant0"] 2 | custom: ["https://paypal.me/dw1s", "https://saweria.co/dwisiswant0", "https://unstoppabledomains.com/d/dwisiswant0.crypto"] 3 | -------------------------------------------------------------------------------- /.github/scripts/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function getCfPrefs() { 4 | curl -s "https://api.bgpview.io/asn/${1}/prefixes" | \ 5 | jq -r '.data.ipv4_prefixes[].parent.prefix' | \ 6 | grep / | sort -u 7 | } 8 | 9 | DB="$(echo -e "$(getCfPrefs "13335")\n$(getCfPrefs "395747")" | sort -u)" 10 | 11 | if [[ "$(echo "${DB}" | wc -l)" != "$(curl -skL "${1}" | wc -l)" ]]; then 12 | echo "${DB}" > db/prefixes.txt 13 | fi 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | 8 | jobs: 9 | build: 10 | name: Build... 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Set up Go 14 | uses: actions/setup-go@v2 15 | with: 16 | go-version: 1.18 17 | 18 | - name: Check out code 19 | uses: actions/checkout@v2 20 | 21 | - name: Build 22 | run: go build . 23 | working-directory: ./ -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | create: 4 | tags: 5 | - v* 6 | 7 | jobs: 8 | release: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: "Check out code" 12 | uses: actions/checkout@v2 13 | with: 14 | fetch-depth: 0 15 | 16 | - name: "Set up Go" 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.18 20 | 21 | - name: "Create release on GitHub" 22 | uses: goreleaser/goreleaser-action@v2 23 | env: 24 | GITHUB_TOKEN: "${{ secrets.RELEASE_TOKEN }}" 25 | with: 26 | args: "release --rm-dist" 27 | version: latest -------------------------------------------------------------------------------- /.github/workflows/update.yaml: -------------------------------------------------------------------------------- 1 | name: Update DB 2 | on: 3 | schedule: 4 | - cron: "0 0 * * 0" # at 00:00 on Sunday 5 | workflow_dispatch: 6 | 7 | jobs: 8 | update: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: "Install dependencies" 12 | run: sudo apt install curl jq -y 13 | 14 | - name: "Check out code" 15 | uses: actions/checkout@v2 16 | with: 17 | fetch-depth: 0 18 | 19 | - name: "Update DB..." 20 | id: update 21 | run: | 22 | ./.github/scripts/update.sh ${{ secrets.LOCAL_DB }} 23 | echo "::set-output name=changes::$(git status -s | wc -l)" 24 | echo "::set-output name=count::$(wc -c < db/prefixes.txt)" 25 | echo "::set-output name=date::$(date)" 26 | 27 | - name: Create Pull Request 28 | if: steps.update.outputs.changes > 0 && steps.update.outputs.count > 1 29 | uses: peter-evans/create-pull-request@v3 30 | with: 31 | body: "Automated update CloudFlare IPv4 prefixes data." 32 | branch-suffix: "short-commit-hash" 33 | branch: "update/db" 34 | commit-message: "db: Update DB ${{ steps.update.date }}" 35 | committer: "Dwi Siswanto " 36 | delete-branch: true 37 | reviewers: "dwisiswant0" 38 | title: "db: Update DB ${{ steps.update.date }}" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cf-check -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | builds: 2 | - binary: cf-check 3 | main: . 4 | goos: 5 | - linux 6 | - windows 7 | - darwin 8 | goarch: 9 | - amd64 10 | - 386 11 | - arm 12 | - arm64 13 | 14 | archives: 15 | - id: tgz 16 | format: tar.gz 17 | replacements: 18 | darwin: macOS 19 | format_overrides: 20 | - goos: windows 21 | format: zip 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 Dwi Siswanto 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## cf-check 2 | Check an Host is Owned by CloudFlare. 3 | 4 | ## Install 5 | 6 | 1. Grab from [releases page](https://github.com/dwisiswant0/cf-check/releases), or 7 | 2. If you have [Go1.18+](https://go.dev/dl/) compiler installed & configured: 8 | 9 | ```console 10 | $ go install github.com/dwisiswant0/cf-check@latest 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```console 16 | $ echo "uber.com" | cf-check 17 | 34.98.127.226 18 | ``` 19 | 20 | or 21 | 22 | ```console 23 | $ cf-check -d 24 | ``` 25 | 26 | ### Flags 27 | 28 | ```console 29 | $ cf-check -h 30 | Usage of cf-check: 31 | -c int 32 | Set the concurrency level (default: 20) 33 | -cf 34 | Show CloudFlare only 35 | -d Print domains instead of IP addresses 36 | ``` 37 | 38 | ## Workaround 39 | 40 | The goal is that you don't need to do a port scan if it's proven that the IP is owned by Cloudflare. 41 | 42 | ```console 43 | $ subfinder -silent -d uber.com | filter-resolved | cf-check -d | anew | naabu -silent -verify | httpx -silent 44 | ``` 45 | 46 | ## License 47 | 48 | `cf-check` is distributed under Apache License 2.0. -------------------------------------------------------------------------------- /check.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "net" 4 | 5 | func isCloudflare(ip net.IP) bool { 6 | for _, c := range cidrs { 7 | if c == "" { 8 | continue 9 | } 10 | 11 | hosts, err := hosts(c) 12 | if err != nil { 13 | continue 14 | } 15 | 16 | for _, host := range hosts { 17 | if host == ip.String() { 18 | return true 19 | } 20 | } 21 | } 22 | return false 23 | } 24 | -------------------------------------------------------------------------------- /db/db.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import "strings" 4 | 5 | func init() { 6 | Prefs = strings.Split(prefs, "\n") 7 | } 8 | -------------------------------------------------------------------------------- /db/prefixes.txt: -------------------------------------------------------------------------------- 1 | 1.0.0.0/24 2 | 1.0.128.0/17 3 | 1.1.1.0/24 4 | 1.1.128.0/17 5 | 1.12.0.0/14 6 | 1.22.0.0/15 7 | 1.38.0.0/15 8 | 1.4.128.0/17 9 | 1.52.0.0/14 10 | 1.66.0.0/15 11 | 103.204.180.0/22 12 | 103.209.140.0/22 13 | 103.21.244.0/22 14 | 103.212.224.0/22 15 | 103.217.92.0/22 16 | 103.219.164.0/22 17 | 103.22.200.0/22 18 | 103.220.16.0/22 19 | 103.229.84.0/22 20 | 103.230.64.0/22 21 | 103.240.136.0/22 22 | 103.243.20.0/22 23 | 103.243.96.0/22 24 | 103.248.80.0/22 25 | 103.249.236.0/22 26 | 103.250.136.0/22 27 | 103.251.216.0/22 28 | 103.253.108.0/22 29 | 103.31.4.0/22 30 | 103.81.228.0/24 31 | 104.153.196.0/22 32 | 104.16.0.0/12 33 | 104.171.160.0/20 34 | 104.192.32.0/21 35 | 104.200.128.0/19 36 | 104.200.96.0/20 37 | 104.201.64.0/18 38 | 104.204.0.0/16 39 | 104.247.32.0/19 40 | 104.37.192.0/21 41 | 104.64.0.0/10 42 | 105.112.0.0/12 43 | 105.128.0.0/11 44 | 105.184.0.0/14 45 | 105.228.0.0/15 46 | 106.75.0.0/16 47 | 106.96.0.0/13 48 | 107.172.0.0/14 49 | 108.162.192.0/18 50 | 109.76.0.0/14 51 | 109.86.0.0/15 52 | 110.174.0.0/15 53 | 110.36.0.0/14 54 | 12.0.0.0/8 55 | 13.104.0.0/14 56 | 139.28.216.0/22 57 | 139.38.0.0/16 58 | 139.61.0.0/16 59 | 14.0.128.0/17 60 | 14.32.0.0/11 61 | 141.101.64.0/18 62 | 141.226.184.0/21 63 | 142.167.0.0/16 64 | 142.229.0.0/16 65 | 160.131.0.0/16 66 | 160.154.0.0/15 67 | 161.213.0.0/16 68 | 161.215.0.0/16 69 | 161.217.0.0/16 70 | 161.239.0.0/16 71 | 161.8.0.0/16 72 | 162.158.0.0/15 73 | 162.208.96.0/22 74 | 162.210.96.0/21 75 | 162.212.24.0/21 76 | 162.213.16.0/22 77 | 162.213.188.0/22 78 | 162.216.44.0/22 79 | 162.217.248.0/22 80 | 162.247.240.0/22 81 | 162.249.240.0/21 82 | 162.251.80.0/22 83 | 162.41.0.0/16 84 | 162.93.0.0/16 85 | 163.171.192.0/18 86 | 164.115.0.0/16 87 | 164.240.0.0/12 88 | 165.166.0.0/16 89 | 165.227.0.0/16 90 | 165.84.128.0/18 91 | 166.21.0.0/16 92 | 166.95.0.0/16 93 | 171.224.0.0/11 94 | 172.111.128.0/17 95 | 172.242.0.0/15 96 | 172.64.0.0/13 97 | 172.83.152.0/21 98 | 172.93.128.0/17 99 | 172.94.0.0/17 100 | 172.96.160.0/23 101 | 173.16.0.0/12 102 | 173.180.0.0/14 103 | 173.195.64.0/20 104 | 173.211.0.0/17 105 | 173.215.0.0/17 106 | 173.222.0.0/15 107 | 173.245.48.0/20 108 | 173.45.0.0/18 109 | 173.47.0.0/16 110 | 174.124.0.0/15 111 | 174.192.0.0/10 112 | 175.100.0.0/17 113 | 175.101.0.0/16 114 | 175.176.0.0/17 115 | 175.180.0.0/14 116 | 176.118.112.0/20 117 | 176.122.128.0/18 118 | 176.123.192.0/20 119 | 176.212.0.0/14 120 | 176.232.0.0/15 121 | 176.28.128.0/17 122 | 176.29.0.0/16 123 | 176.33.0.0/16 124 | 176.47.0.0/16 125 | 176.54.0.0/15 126 | 176.56.0.0/19 127 | 176.57.248.0/21 128 | 176.62.0.0/19 129 | 176.62.176.0/20 130 | 176.65.96.0/19 131 | 185.146.172.0/22 132 | 188.114.96.0/20 133 | 189.240.0.0/12 134 | 190.40.0.0/17 135 | 190.93.240.0/20 136 | 195.242.122.0/23 137 | 196.176.0.0/14 138 | 197.136.0.0/14 139 | 197.160.0.0/13 140 | 197.234.240.0/22 141 | 198.217.250.0/23 142 | 198.41.128.0/17 143 | 198.61.96.0/19 144 | 199.27.128.0/21 145 | 2.176.0.0/12 146 | 2.92.0.0/14 147 | 200.75.160.0/20 148 | 23.227.32.0/19 149 | 5.101.112.0/20 150 | 5.16.0.0/14 151 | 5.252.236.0/22 152 | 5.254.0.0/17 153 | 5.254.160.0/21 154 | 5.53.128.0/17 155 | 5.8.16.0/21 156 | 6.0.0.0/8 157 | 64.68.192.0/20 158 | 65.110.56.0/21 159 | 66.235.200.0/24 160 | 68.67.64.0/20 161 | 8.0.0.0/9 162 | 8.244.0.0/14 163 | 91.234.214.0/24 164 | -------------------------------------------------------------------------------- /db/vars.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import _ "embed" 4 | 5 | var ( 6 | //go:embed prefixes.txt 7 | prefs string 8 | Prefs []string 9 | ) 10 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dwisiswant0/cf-check 2 | 3 | go 1.18 4 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "net" 7 | "net/url" 8 | "os" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | concurrency := 20 14 | 15 | flag.IntVar(&concurrency, "c", concurrency, "Set the concurrency level") 16 | flag.BoolVar(&domainMode, "d", false, "Print domains instead of IP addresses") 17 | flag.BoolVar(&showCloudflare, "cf", false, "Show CloudFlare only") 18 | flag.Parse() 19 | 20 | jobs := make(chan string) 21 | 22 | for i := 0; i < concurrency; i++ { 23 | wg.Add(1) 24 | 25 | go func() { 26 | for host := range jobs { 27 | addr, err := net.LookupIP(strings.TrimSpace(host)) 28 | if err != nil { 29 | continue 30 | } 31 | 32 | ip := addr[0] 33 | cf := isCloudflare(ip) 34 | 35 | if !cf && !showCloudflare { 36 | show(host, ip, domainMode) 37 | } else if cf && showCloudflare { 38 | show(host, ip, domainMode) 39 | } 40 | } 41 | 42 | defer wg.Done() 43 | }() 44 | } 45 | 46 | fn := flag.Arg(0) 47 | 48 | if isStdin() { 49 | sc = bufio.NewScanner(os.Stdin) 50 | } else if fn != "" { 51 | r, err := os.Open(fn) 52 | if err != nil { 53 | panic(err) 54 | } 55 | 56 | sc = bufio.NewScanner(r) 57 | } else { 58 | return 59 | } 60 | 61 | for sc.Scan() { 62 | i := sc.Text() 63 | u, err := url.Parse(i) 64 | if err == nil { 65 | if u.Host != "" { 66 | jobs <- u.Host 67 | } else { 68 | jobs <- i 69 | } 70 | } 71 | } 72 | 73 | close(jobs) 74 | wg.Wait() 75 | } 76 | -------------------------------------------------------------------------------- /utils.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "os" 7 | ) 8 | 9 | func show(host string, ip net.IP, mode bool) { 10 | if mode { 11 | fmt.Println(host) 12 | } else { 13 | fmt.Println(ip) 14 | } 15 | } 16 | 17 | func inc(ip net.IP) { 18 | for j := len(ip) - 1; j >= 0; j-- { 19 | ip[j]++ 20 | if ip[j] > 0 { 21 | break 22 | } 23 | } 24 | } 25 | 26 | func hosts(cidr string) ([]string, error) { 27 | ip, ipnet, err := net.ParseCIDR(cidr) 28 | if err != nil { 29 | return nil, err 30 | } 31 | 32 | var ips []string 33 | for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) { 34 | ips = append(ips, ip.String()) 35 | } 36 | 37 | lenIPs := len(ips) 38 | switch { 39 | case lenIPs < 2: 40 | return ips, nil 41 | default: 42 | return ips[1 : len(ips)-1], nil 43 | } 44 | } 45 | 46 | func isStdin() bool { 47 | f, e := os.Stdin.Stat() 48 | if e != nil { 49 | return false 50 | } 51 | 52 | if f.Mode()&os.ModeNamedPipe == 0 { 53 | return false 54 | } 55 | 56 | return true 57 | } 58 | -------------------------------------------------------------------------------- /vars.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "sync" 6 | 7 | "github.com/dwisiswant0/cf-check/db" 8 | ) 9 | 10 | var ( 11 | wg sync.WaitGroup 12 | sc *bufio.Scanner 13 | 14 | domainMode, showCloudflare bool 15 | 16 | cidrs = db.Prefs 17 | ) 18 | --------------------------------------------------------------------------------