From fa0ad38cdf4b6a8a2dbfeea90edc976b03203a40 Mon Sep 17 00:00:00 2001 From: iBug Date: Thu, 21 Nov 2019 15:36:57 +0800 Subject: [PATCH] Last maintenance to this repository, see README --- README.md | 8 ++++++-- build.sh | 7 ------- code.js | 25 +++++++++++++++++++------ ip_ranges.txt | 22 +++++++++++++++------- ranges_to_js.py | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d733487..766fc45 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # pac -PAC scripts for proxies. +PAC scripts for proxies -To generate PAC from the latest IP range list, run `./build.sh` (make sure you have `wget` and Python 3 available). +## 使用 + +为了方便大家生成与使用,我制作了一个网页版的生成器:,可以直接在线生成并下载。 + +网页生成器的源代码[在这](https://github.com/iBug/iBug-source/blob/master/_cn/pac-generator.md),同时本仓库中的代码停止维护。 diff --git a/build.sh b/build.sh index c2fd70a..956303e 100755 --- a/build.sh +++ b/build.sh @@ -3,13 +3,6 @@ SOURCE="http://www.ipdeny.com/ipblocks/data/aggregated/cn-aggregated.zone" wget -O ip_ranges.txt "$SOURCE" -cat >> ip_ranges.txt < tmp.js cat code.js tmp.js > out.pac rm tmp.js diff --git a/code.js b/code.js index c02b31c..01db4b1 100644 --- a/code.js +++ b/code.js @@ -23,18 +23,31 @@ function belongsToSubnet(host, list) { return (masked ^ list[x][0]) == 0; } -var proxy = "__PROXY__"; -var direct = "DIRECT"; +function isChina(host) { + return belongsToSubnet(host, CHINA); +} + +function isLan(host) { + return belongsToSubnet(host, LAN); +} function FindProxyForURL(url, host) { var remote = dnsResolve(host); - if (belongsToSubnet(remote, WHITELIST)) { - return direct; + if (isLan(remote) || isChina(remote)) { + return "DIRECT"; } - return proxy; + return "__PROXY__"; } // Format: [Hex IP, mask] -// e.g. 1.0.1.0/24 = [0x80008000, 0xFFFFFF00] +// e.g. 1.0.1.0/24 = [0x01000100, 0xFFFFFF00] // Source: http://www.ipdeny.com/ipblocks/data/aggregated/cn-aggregated.zone +var LAN = [ + [0x0A000000, 0xFF000000], + [0x7F000000, 0xFFFFFF00], + [0xA9FE0000, 0xFFFF0000], + [0xAC100000, 0xFFF00000], + [0xC0A80000, 0xFFFF0000] +]; + diff --git a/ip_ranges.txt b/ip_ranges.txt index 1dd74a3..e4f1b5a 100644 --- a/ip_ranges.txt +++ b/ip_ranges.txt @@ -883,7 +883,10 @@ 101.2.172.0/22 101.4.0.0/14 101.16.0.0/12 -101.32.0.0/12 +101.33.128.0/17 +101.34.0.0/15 +101.36.0.0/14 +101.40.0.0/13 101.48.0.0/15 101.50.8.0/21 101.50.56.0/22 @@ -2034,7 +2037,6 @@ 103.126.208.0/22 103.126.241.0/24 103.129.52.0/22 -103.129.148.0/22 103.130.132.0/22 103.130.152.0/24 103.130.160.0/22 @@ -2155,6 +2157,17 @@ 103.144.88.0/24 103.144.108.0/23 103.144.136.0/23 +103.144.148.0/23 +103.144.158.0/23 +103.144.240.0/23 +103.145.38.0/23 +103.145.40.0/22 +103.145.60.0/23 +103.145.72.0/23 +103.145.80.0/23 +103.145.86.0/23 +103.145.92.0/22 +103.145.98.0/23 103.192.0.0/19 103.192.48.0/21 103.192.56.0/22 @@ -5227,8 +5240,3 @@ 223.255.0.0/17 223.255.236.0/22 223.255.252.0/23 -10.0.0.0/8 -127.0.0.0/16 -129.254.0.0/16 -172.16.0.0/12 -192.168.0.0/16 diff --git a/ranges_to_js.py b/ranges_to_js.py index b910913..bc60bf7 100644 --- a/ranges_to_js.py +++ b/ranges_to_js.py @@ -18,6 +18,6 @@ data = [(ip_to_num(s), n_to_mask(int(n))) for s, n in pairs] data = sorted(data, key=lambda x: x[0]) out = ",\n".join([" [{}, {}]".format(to_upper_hex(a), to_upper_hex(b)) for a, b in data]) -out = "var WHITELIST = [\n" + out + "\n];" +out = "var CHINA = [\n" + out + "\n];" print(out)