├── .github ├── dependabot.yml └── workflows │ └── main.yml ├── LICENSE └── README.md /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | timezone: "Asia/Shanghai" 13 | time: "07:00" 14 | pull-request-branch-name: 15 | separator: "-" 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 ChanthMiao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # China-IPv4-List 2 | 3 | 中国大陆IPv4地址库 4 | 5 | ## 说明 6 | 7 | 本项目为[gaoyifan/china-operator-ip](https://github.com/gaoyifan/china-operator-ip)的个人重构,和原项目有以下不同: 8 | 9 | - 移除了具体的运营商分类,仅保留了中国大陆IPv4地址 10 | - 构建流程完全迁移至Github Action,北京时间每日6:00自动构建 11 | 12 | 此外,因和 CC-BY-NC-SA 4.0 协议存在[兼容问题](https://creativecommons.org/share-your-work/licensing-considerations/compatible-licenses),本项目未合并[ipip免费提供的数据](https://github.com/17mon/china_ip_list)。 13 | 14 | ## 下载地址 15 | 16 | > 2023.01.24 更新: 因 [jsdelivr 大陆服务节点关闭](https://luotianyi.vc/6295.html),移除相应 CDN 链接。 17 | 18 | - cn.txt: 19 | - 20 | - cn.txt.sha256sum: 21 | - 22 | 23 | ## 致谢 24 | 25 | - 感谢[gaoyifan/china-operator-ip](https://github.com/gaoyifan/china-operator-ip)项目提供的具体实现方法 26 | - 感谢[Loyalsoldier/geoip](https://github.com/Loyalsoldier/geoip)项目提供的 Github Action 编写参考 27 | - 感谢[actions/checkout](https://github.com/actions/checkout/discussions/479)提供的 github-actions bot 正确用法 28 | 29 | ## License 30 | 31 | The code in this repository is licensed under the [MIT License](https://github.com/ChanthMiao/China-IPv4-List/blob/main/LICENSE). 32 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: Build China IPv4 list. 4 | 5 | # Controls when the workflow will run 6 | on: 7 | workflow_dispatch: 8 | schedule: 9 | - cron: "0 22 * * *" 10 | push: 11 | branches: 12 | - main 13 | paths-ignore: 14 | - "**/README.md" 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | env: 24 | GO111MODULE: on 25 | 26 | # Steps represent a sequence of tasks that will be executed as part of the job 27 | steps: 28 | - name: Setup Go environment 29 | uses: actions/setup-go@v5 30 | 31 | - name: Setup Rust environmet 32 | uses: dtolnay/rust-toolchain@stable 33 | 34 | - name: Install packages. 35 | run: | 36 | sudo apt-get update && sudo apt-get install -y bgpdump 37 | cargo install --vers 0.0.3 bgptools 38 | go install github.com/zhanhb/cidr-merger@v1.1.3 39 | shell: bash 40 | 41 | - name: Set variables 42 | run: | 43 | echo "PATH=$(go env GOPATH)/bin:${PATH}" >> $GITHUB_ENV 44 | echo "RELEASE_NAME=$(date -u +%Y.%m.%d)" >> $GITHUB_ENV 45 | shell: bash 46 | 47 | - name: Checkout main branch 48 | uses: actions/checkout@v4 49 | with: 50 | ref: main 51 | path: code 52 | 53 | - name: Generate AS table 54 | run: curl -sSL https://bgp.potaroo.net/cidr/autnums.html | awk '-F[<>]' '{print $3,$5}' | grep '^AS' > asnames.txt 55 | shell: bash 56 | 57 | - name: Fetch bgp data. 58 | run: | 59 | wget -O rib.bz2 "http://archive.routeviews.org/dnszones/rib.bz2" 60 | 61 | - name: Dump bgp date. 62 | run: | 63 | echo "running bgpdump ..." 64 | bgpdump -m -O rib.txt rib.bz2 65 | echo "finish bgpdump" 66 | shell: bash 67 | 68 | - name: Generate China IPv4 list 69 | run: | 70 | cat asnames.txt|grep -P "CN\$"|grep -vPi "AS45102"|awk '{gsub(/AS/, ""); print $1}' > cnasn.list 71 | cat cnasn.list|xargs bgptools -b rib.txt|cidr-merger -s|grep -Fv ':' > cn.txt 72 | shell: bash 73 | 74 | - name: Generate cn.txt sha256 hash 75 | run: | 76 | sha256sum cn.txt > cn.txt.sha256sum 77 | shell: bash 78 | 79 | - name: Checkout release branch 80 | uses: actions/checkout@v4 81 | with: 82 | ref: release 83 | path: release 84 | 85 | - name: Git push assets to "release" branch 86 | if: ${{ github.event_name == 'schedule' }} 87 | run: | 88 | mv cn.txt release/ 89 | mv cn.txt.sha256sum release/ 90 | cd release 91 | git config user.name 'github-actions[bot]' 92 | git config user.email 'github-actions[bot]@users.noreply.github.com' 93 | git add . 94 | [ -n "$(git status -s)" ] && git commit -m "${{ env.RELEASE_NAME }}" || echo "Nothing to commit!" 95 | git push 96 | shell: bash 97 | --------------------------------------------------------------------------------