A Python script that generates regional IP (IPv4) addresses per CIDR notation.. You import such IP addresses as whitelists into bypassing tools for full access of internet.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Disclaimer / 声明

The information (including but not limited to: documentation, code, and data) under this repository is not provided for any specific purpose, and should not be relied upon. While the author aims to keep information under this repository current, it is provided "as is" and there are no responsibilities or warranties as to the accuracy, fitness, or authorativeness regarding this repository. The author will not be liable or responsible to any one for any loss or damage arising under or in connection with: use of, or inability to use, the information under this repository, regardless of the origins of such content.


Introduction / 介绍

A Python script that generates regional IP (IPv4) addresses per CIDR notation. You import such IP addresses as whitelists into bypassing tools for full access of internet.

本Python脚本用于生成CIDR格式的地区内的IP (IPv4)地址块。这些IP地址将可作为白名单被导入工具中,从而生成根据目标IP地址区域的路由表,最终目标是构建一个快速、无缝、相对稳定的上网工具。

Intended Audience / 目标用户

This tool should be used by advanced users who has knowledge regarding networking and system administration. We assume our users are equipped with basic skills of setting up network-bypassing tools and routing table configuration. We recommend users with average IT proficiency use this tool under the guidance of your geek friends. Additionally, please keep in mind: this tool is never intended to become any firewall-bypassing / IP disguising tool by itself.


How it works / 工作原理

This tool would grab a list IP addresses from the website of APNIC. Such list associates IP addresses with corresponding regions/countries. Then, it would parse the list, filters out IP addresses within a certain region, then converts it into CIDR nodation. After retrieving the set IP addresses inside a specified region, it would derive those IP addresses ourside that region by calculating the complement set. (Of course, those reserved IP addresses would also be excluded from the complement set.) Finally, both IP addresses inside region and the ones outside it would be written into a file, respectively.

本工具将从APNIC官网抓取与国家或地区相对应的IP地址列表。在将IP列表进行解析,筛选出一个特定地区内的IP地址,并且转化为 CIDR 格式. 在得到某一 区内 的所有IP地址之后,本工具还将对其进行补集运算,以得到地区 区外 的所有IP地址。(当然, 保留的IP 地址会在补集中去除) 。最终,区内和区外的IP地址列表将分别写入文件中。

Getting Started / 开始使用

End users / 普通用户

You could simply download those files under the output folder under this repo, and use it as the "whitelist" for your :

  • output/inwall.txt contains IP addresses assigned / allocated to mainland China
  • output/outwall.txt contains IP addresses rest of the world (excluding reserved IP addresses)

直接调用本Github repo下的output文件夹下的文件,并将

  • output/inwall.txt 包含墙内的IP地址
  • output/outwall.txt 包含墙外的IP地址;那些已经在RFC中被保留的地址已经被去除

Advanced Users & Developers / 开发者

  1. Make sure Python 3 is properly installed.
  2. git clone this project, or just download the .zip file from github.com and unarchive it, so as to make the project's base folder
  3. Start CLI (DOS-like command line interface, such as Command Prompt in Windows), enter the the project's base folder
  4. Setup Python virtual environment with virtualenv ... or python -m venv ...
  5. Run: pip install -r requirements.txt
  6. Run: python ipv4cn.py

... ... ...

  1. 确保系统上已经有Python 3(抱歉,不支持Python 2.x)
  2. git clone 本代码库
  3. 在命令行中,进入本项目的文件夹目录
  4. 设置并加载 venv / virtualenv
  5. 运行 pip install -r requirements.txt 以加载requests等第三方模块
  6. 运行 python ipv4cn.py

FAQ / 常见问答

1. What's the benefit of using IP whitelists? / 使用IP地址的白名单有什么好处?

A: / 答:

Everyone wants fast, smooth, reliable internet access. This is expecially crucial for expatriates, IT professionals, and scholars living in China. Currently, most firewall-bypassing tools unconditionally route all traffic through indirect channels (or contains outdated IP tables), which has side-effects such as low thoroughput, long latency, or even restrictions from IP-distinguishing music or video websites. This repo aims to provide an IP whitelist, which can be in turn used by firewall-bypassing tools capable of distinguishing destination, and therefore providing a better solution without such side-effects.


2. How would you compare this tool with peers? / 与同类工具如何比较?

A: / 答:

We are fully aware that there are some pieces of existing wheels that can achieve the task very well. For example, the one-line shell script below can generate the CIDR blocks for mainland China -- like a magic, huh? Yet we also believe that there are other features not covered by exisiting code -- The outwall.txt, IP addresses rest of the world, would be a perfect example.


curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > chnroute.txt

Random Thoughts / 随笔


           ———— 《沁园春·雪》