mirror of
https://github.com/iBug/pac.git
synced 2025-07-13 21:02:16 +08:00
Rearrange repository content
This commit is contained in:
parent
d21740918d
commit
290db4052d
8
build.sh
8
build.sh
@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SOURCE="http://www.ipdeny.com/ipblocks/data/aggregated/cn-aggregated.zone"
|
||||
|
||||
wget -O ip_ranges.txt "$SOURCE"
|
||||
python3 ranges_to_js.py > tmp.js
|
||||
cat code.js tmp.js > out.pac
|
||||
rm tmp.js
|
File diff suppressed because it is too large
Load Diff
20
code.js
20
code.js
@ -1,4 +1,5 @@
|
||||
// Author: iBug
|
||||
// Author: iBug <ibugone.com>
|
||||
// Time: @@TIME@@
|
||||
|
||||
function belongsToSubnet(host, list) {
|
||||
var ip = host.split(".");
|
||||
@ -31,21 +32,24 @@ function isLan(host) {
|
||||
return belongsToSubnet(host, LAN);
|
||||
}
|
||||
|
||||
var proxy = "__PROXY__";
|
||||
var direct = "DIRECT";
|
||||
// Attempt to catch Shadowsocks-Windows 4.1.9
|
||||
if (typeof __PROXY__ !== "undefined") {
|
||||
proxy = __PROXY__;
|
||||
}
|
||||
|
||||
function FindProxyForURL(url, host) {
|
||||
if (!isResolvable(host)) {
|
||||
return proxy;
|
||||
return proxy;
|
||||
}
|
||||
var remote = dnsResolve(host);
|
||||
if (isLan(remote) || isChina(remote)) {
|
||||
return "DIRECT";
|
||||
return direct;
|
||||
}
|
||||
return "__PROXY__";
|
||||
return proxy;
|
||||
}
|
||||
|
||||
// Format: [Hex IP, mask]
|
||||
// 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],
|
||||
|
5242
ip_ranges.txt
5242
ip_ranges.txt
File diff suppressed because it is too large
Load Diff
@ -1,23 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
def ip_to_num(s):
|
||||
return sum([int(n) * (256 ** int(e)) for e, n in enumerate(s.split(".")[::-1])])
|
||||
|
||||
def n_to_mask(n):
|
||||
return (2**32 - 1) >> (32 - n) << (32 - n)
|
||||
|
||||
def to_upper_hex(n):
|
||||
return "{:#010X}".format(n).replace("X", "x")
|
||||
|
||||
with open("ip_ranges.txt", "r") as f:
|
||||
text = f.read()
|
||||
|
||||
lines = [line for line in text.split("\n") if line]
|
||||
pairs = [p.split("/") for p in lines]
|
||||
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 CHINA = [\n" + out + "\n];"
|
||||
|
||||
print(out)
|
Loading…
Reference in New Issue
Block a user