Compare commits

...

55 Commits

Author SHA1 Message Date
GitHub Action
b555c5f501 定期更新数据并生成 gfw.pac 2025-06-19 00:38:18 +00:00
GitHub Action
c326290d19 定期更新数据并生成 gfw.pac 2025-06-12 00:37:29 +00:00
GitHub Action
a0492f01dd 定期更新数据并生成 gfw.pac 2025-06-05 00:37:44 +00:00
GitHub Action
1ef7a4092d 定期更新数据并生成 gfw.pac 2025-05-29 00:37:04 +00:00
GitHub Action
d5a92c3623 定期更新数据并生成 gfw.pac 2025-05-22 00:36:49 +00:00
GitHub Action
0d3a81c98a 定期更新数据并生成 gfw.pac 2025-05-15 00:36:01 +00:00
GitHub Action
48b691f648 定期更新数据并生成 gfw.pac 2025-05-08 00:36:59 +00:00
GitHub Action
b08e659514 定期更新数据并生成 gfw.pac 2025-05-01 00:40:47 +00:00
GitHub Action
1a511c81ef 定期更新数据并生成 gfw.pac 2025-04-24 00:35:46 +00:00
GitHub Action
e084116209 定期更新数据并生成 gfw.pac 2025-04-17 00:35:28 +00:00
GitHub Action
64f75179f5 自动生成 gfw.pac: 增加gr.global.aa-rt.sharepoint.com到onedrive直连域名 2025-04-10 05:23:58 +00:00
zhiyi
948a002d73 增加gr.global.aa-rt.sharepoint.com到onedrive直连域名 2025-04-10 13:23:46 +08:00
GitHub Action
046401ec20 定期更新数据并生成 gfw.pac 2025-04-10 00:34:51 +00:00
GitHub Action
9cf413c43c 定期更新数据并生成 gfw.pac 2025-04-03 00:34:34 +00:00
GitHub Action
601b549b31 定期更新数据并生成 gfw.pac 2025-03-27 00:34:35 +00:00
GitHub Action
6b65baa275 定期更新数据并生成 gfw.pac 2025-03-20 00:33:42 +00:00
GitHub Action
8c52b77a03 定期更新数据并生成 gfw.pac 2025-03-13 00:34:11 +00:00
GitHub Action
02f24366f5 定期更新数据并生成 gfw.pac 2025-03-06 00:33:48 +00:00
GitHub Action
419485dde2 定期更新数据并生成 gfw.pac 2025-02-27 00:33:11 +00:00
GitHub Action
2a1c178d3a 定期更新数据并生成 gfw.pac 2025-02-20 00:32:57 +00:00
GitHub Action
ab03a97789 定期更新数据并生成 gfw.pac 2025-02-13 00:32:19 +00:00
GitHub Action
ac4fb7b19b 定期更新数据并生成 gfw.pac 2025-02-06 00:32:21 +00:00
GitHub Action
f810a66b0c 定期更新数据并生成 gfw.pac 2025-01-30 00:31:19 +00:00
GitHub Action
e6129a6dd4 定期更新数据并生成 gfw.pac 2025-01-23 00:31:48 +00:00
GitHub Action
f1df8acaba 定期更新数据并生成 gfw.pac 2025-01-16 00:31:43 +00:00
GitHub Action
7add95746e 定期更新数据并生成 gfw.pac 2025-01-09 00:32:39 +00:00
GitHub Action
9622bd4456 定期更新数据并生成 gfw.pac 2025-01-02 00:32:02 +00:00
GitHub Action
3949a407b0 定期更新数据并生成 gfw.pac 2024-12-26 00:31:59 +00:00
GitHub Action
8b51175a34 定期更新数据并生成 gfw.pac 2024-12-19 00:34:09 +00:00
GitHub Action
bdc53dd5ca 定期更新数据并生成 gfw.pac 2024-12-12 00:35:00 +00:00
zhiyi
f3d1085c2d 改改workflow 2024-12-05 17:59:43 +08:00
GitHub Action
932d427c01 自动生成 gfw.pac: 简单压缩,生成的文件中相邻的前缀相同前缀字符用波浪线替代,最终文件缩减又110k,目前116k。未经完全测试。 2024-12-05 09:44:21 +00:00
zhiyi
d554c444cc 简单压缩,生成的文件中相邻的前缀相同前缀字符用波浪线替代,最终文件缩减又110k,目前116k。未经完全测试。 2024-12-05 17:44:00 +08:00
GitHub Action
7b9fb28619 自动生成 gfw.pac: CIDR只保留构建树所需的前缀位,减少最终文件体积约100k;树底层使用map替代object提高大约7倍查询效率(实际单次查询差距绝对值在0.002ms以下,无意义的优化) 2024-12-04 09:02:41 +00:00
zhiyi
74e6d0aa47 CIDR只保留构建树所需的前缀位,减少最终文件体积约100k;树底层使用map替代object提高大约7倍查询效率(实际单次查询差距绝对值在0.002ms以下,无意义的优化) 2024-12-04 17:02:21 +08:00
GitHub Action
509f516d1d 定期更新数据并生成 gfw.pac 2024-11-28 00:34:25 +00:00
GitHub Action
4ae3541f20 定期更新数据并生成 gfw.pac 2024-11-21 00:33:34 +00:00
GitHub Action
58d793c13c 定期更新数据并生成 gfw.pac 2024-11-14 00:31:57 +00:00
GitHub Action
340754f759 定期更新数据并生成 gfw.pac 2024-11-07 00:31:32 +00:00
GitHub Action
d36a5097f5 定期更新数据并生成 gfw.pac 2024-10-31 00:32:39 +00:00
GitHub Action
03998c2db0 定期更新数据并生成 gfw.pac 2024-10-24 00:31:52 +00:00
zhiyi
bc33e69e7d fix auto-generate-pac bug 2024-10-17 16:18:15 +08:00
GitHub Action
fcd1ce19aa 自动生成 gfw.pac: onedrive客户端部分域名加入直连名单 2024-10-17 07:35:59 +00:00
zhiyi
d923c54720 onedrive客户端部分域名加入直连名单 2024-10-17 15:35:36 +08:00
GitHub Action
16f2713aa1 定期更新数据并生成 gfw.pac 2024-10-17 00:31:46 +00:00
zhiyi
07a9e9773b 优化workflow 2024-10-10 20:14:07 +08:00
zhiyi
f827e221e7 优化workflow 2024-10-10 17:35:05 +08:00
GitHub Action
357bbd09bd 自动生成 gfw.pac: 自动生成 gfw.pac: 添加部分小红书和字节系域名 2024-10-10 00:31:17 +00:00
GitHub Action
a283940216 自动生成 gfw.pac: 添加部分小红书和字节系域名 2024-10-05 23:58:34 +00:00
zhiyi
4a64f36f5c 添加部分小红书和字节系域名 2024-10-06 07:58:18 +08:00
GitHub Action
34b4cd9097 自动生成 gfw.pac: add ig whatsapp reddit to proxy-domains 2024-10-05 23:13:48 +00:00
zhiyi
812b8e7d4c add ig whatsapp reddit to proxy-domains 2024-10-06 07:13:33 +08:00
GitHub Action
0ab915b467 自动生成 gfw.pac: 代理域名列表添加一个bing相关的域名 2024-10-05 09:18:21 +00:00
zhiyi
87d75dba5f 代理域名列表添加一个bing相关的域名 2024-10-05 17:18:05 +08:00
zhiyi
3027e9e6a7 优化workflow 2024-10-04 05:00:57 +08:00
8 changed files with 4494 additions and 3153 deletions

View File

@@ -4,12 +4,13 @@ on:
schedule:
- cron: '10 0 * * 4'
push:
paths-ignore:
- 'README.md'
- 'LICENSE'
- 'gfw.pac'
- '.gitignore'
- '.github/**'
paths:
- 'gfw-pac.py'
- 'pac-template'
- 'local-tlds.txt'
- 'direct-domains.txt'
- 'proxy-domains.txt'
- 'cidrs-cn.txt'
workflow_dispatch:
jobs:
@@ -19,21 +20,36 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if gfw.pac is in the commit
id: check-file
run: |
if git diff --name-only HEAD^ HEAD | grep -q 'gfw\.pac'; then
echo "file-exists=true" >> $GITHUB_ENV
else
echo "file-exists=false" >> $GITHUB_ENV
fi
- name: Download the latest cn.txt
if: env.file-exists == 'false'
run: curl -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/cn.txt -o cidrs-cn.txt
- name: Run gfw-pac.py script
if: env.file-exists == 'false'
run: ./gfw-pac.py -f gfw.pac -p "PROXY 127.0.0.1:3128" --proxy-domains=proxy-domains.txt --direct-domains=direct-domains.txt --localtld-domains=local-tlds.txt --ip-file=cidrs-cn.txt
- name: Commit and push changes
if: env.file-exists == 'false'
run: |
last_commit_message=$(git log -1 --pretty=%B)
commit_message=$([[ "${{ github.event_name }}" == "schedule" ]] && echo "定期更新数据并生成 gfw.pac" || echo "自动生成 gfw.pac: $last_commit_message")
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git commit -a -m "自动生成 gfw.pac"
git commit -a -m "${commit_message}"
git push
- name: Trigger Auto-Release
if: env.file-exists == 'false'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Auto Generate Release

2
.gitignore vendored
View File

@@ -43,3 +43,5 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
test.js

View File

File diff suppressed because it is too large Load Diff

View File

@@ -69,8 +69,18 @@ douyinstatic.com
douyinvod.com
supercachenode.com
bytedance.com
bytedanceapi.com
bytescm.com
bytecdn.cn
byteoc.com
bytednsdoc.com
bytetcc.com
feishu.cn
feishucdn.com
toutiao.com
toutiaoimg.com
toutiaostatic.com
yhgfb-cn-static.com
cmbchina.com
mi.com
xiaomi.com
@@ -83,6 +93,8 @@ dianping.com
quark.cn
wps.cn
wpscdn.cn
xiaohongshu.com
xhscdn.com
push.apple.com
setup.icloud.com
appldnld.apple.com
@@ -117,4 +129,11 @@ browser.events.data.microsoft.com
ocsp.globalsign.com
ocsp2.globalsign.com
ocsp.digicert.cn
ocsp.dcocsp.cn
ocsp.dcocsp.cn
api.onedrive.com
storage.live.com
gr.global.aa-rt.sharepoint.com
skyapi.live.net
roaming.officeapps.live.com
blob.core.windows.net
default.exp-tas.com

View File

@@ -27,16 +27,18 @@ def parse_args():
def convert_cidr(cidr):
if '/' in cidr:
network = ipaddress.ip_network(cidr.strip(), strict=False)
network_address = network.network_address
prefixlen = network.prefixlen
network_address = int(network.network_address) >> (network.max_prefixlen - network.prefixlen)
else:
network = ipaddress.ip_address(cidr.strip())
network_address = network
prefixlen = network.max_prefixlen
if network.version == 4:
return hex(int(network_address))[2:] + '/' + str(prefixlen)
else:
return network.compressed
return hex(int(network_address))[2:]
def longest_common_prefix(str1, str2):
min_length = min(len(str1), len(str2))
for i in range(min_length):
if str1[i] != str2[i]:
return str1[:i]
return str1[:min_length]
def generate_cnip_cidrs():
""" 从文件中读取CIDR地址 """
@@ -47,6 +49,22 @@ def generate_cnip_cidrs():
for cidr in cidrs:
converted_cidrs.append(convert_cidr(cidr))
converted_cidrs.sort(key=lambda x: (len(x), x), reverse=False)
converted_cidrs_clone = converted_cidrs[:]
lastFullCidr = ''
for i in range(len(converted_cidrs)):
prevCidr = converted_cidrs_clone[i-1] if i > 0 else ''
currentCidr = converted_cidrs[i]
if len(prevCidr) != len(currentCidr):
lastFullCidr = currentCidr
continue
prefix = longest_common_prefix(lastFullCidr, currentCidr)
if len(prefix) < len(lastFullCidr)//1.2:
lastFullCidr = currentCidr
continue
converted_cidrs[i] = '~' + currentCidr[len(prefix):]
cidr_list = ','.join(converted_cidrs)
return f"'{cidr_list}'.split(',')"

76
gfw.pac
View File

File diff suppressed because one or more lines are too long

View File

@@ -10,35 +10,45 @@ var localTlds = __LOCAL_TLDS__;
var cidrs = __CIDRS__;
var hasOwnProperty = Object.hasOwnProperty;
function isIpAddress(ip) {
return /^\d{1,3}(\.\d{1,3}){3}$/.test(ip) || /^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$/.test(ip);
}
function RadixTree() {
this.root = {};
this.root = new Map();
}
RadixTree.prototype.insert = function(string) {
var node = this.root;
for (var i = 0; i < string.length; i++) {
var char = string[i];
if (!node[char]) {
node[char] = {};
if (!node.has(char)) {
node.set(char, new Map());
}
node = node[char];
node = node.get(char);
}
};
RadixTree.prototype.to_list = function() {
return this.root;
};
RadixTree.prototype.search = function(string) {
var currentNode = this.root;
var isLastNode = false;
for (var i=0; i < string.length; i++) {
var char = string[i];
if (currentNode.has(char)) {
currentNode = currentNode.get(char);
isLastNode = currentNode.size === 0;
} else {
break;
}
}
return isLastNode;
}
function ipToBinary(ip) {
var bin = ''
// Check if it's IPv4
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(ip)) {
return ip.split('.').map(function(num) {
bin = ip.split('.').map(function(num) {
return ("00000000" + parseInt(num, 10).toString(2)).slice(-8);
}).join('');
} else if (/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$/.test(ip)) {
@@ -54,25 +64,11 @@ function ipToBinary(ip) {
var fullAddress = left.concat(Array(zeroGroups + 1).join('0').split('')).concat(right);
// Convert each group to binary and pad to 16 bits
return fullAddress.map(function(group) {
bin = fullAddress.map(function(group) {
return ("0000000000000000" + parseInt(group || '0', 16).toString(2)).slice(-16);
}).join('');
}
}
function searchRadixTree(bits) {
var currentNode = radixTree;
var isLastNode = false;
for (var i=0; i<bits.length; i++) {
var char = bits[i];
if (currentNode[char]) {
currentNode = currentNode[char];
isLastNode = Object.keys(currentNode).length === 0;
} else {
break;
}
}
return isLastNode;
return bin.replace(/^0+/, '');
}
function isInDirectDomain(host) {
@@ -142,7 +138,7 @@ function FindProxyForURL(url, host) {
} else if (isPrivateIp(ip)) {
debug('域名解析后命中私有 IP 地址', host, ip);
return direct;
} else if (searchRadixTree(ipToBinary(ip))) {
} else if (radixTree.search(ipToBinary(ip))) {
debug('匹配到直连IP', host, ip);
return direct;
}
@@ -152,7 +148,7 @@ function FindProxyForURL(url, host) {
}
var allowAlert = true
function debug(msg, host, ip) {
function debug(msg, host='', ip='') {
if (!allowAlert) {
return
}
@@ -166,19 +162,17 @@ function debug(msg, host, ip) {
var radixTree = new RadixTree();
(function () {
var startTime = new Date().getMilliseconds();
debug('开始生成 Radix Tree', 'PAC文件载入开始', startTime.toString());
debug('开始生成 Radix Tree', 'PAC文件载入开始');
lastFullPrefix = ''
for (let i=0; i<cidrs.length; i++) {
var cidr = cidrs[i];
var [ip, prefixLen] = cidr.split('/');
if (!cidr.includes(':')) {
var ip = ip.match(/.{1,2}/g).map(function(byte) {
return parseInt(byte, 16);
}).join('.');
var prefix = cidrs[i];
if (prefix.substring(0, 1) !== '~') {
lastFullPrefix = prefix
} else {
prefix = lastFullPrefix.substring(0, lastFullPrefix.length-prefix.length+1) + prefix.substring(1)
}
var bits = ipToBinary(ip).slice(0, prefixLen);
var bits = (parseInt(prefix, 16)).toString(2);
radixTree.insert(bits);
}
radixTree = radixTree.to_list();
debug('Radix Tree 已生成', 'PAC文件载入完毕', cidrs.length.toString()+'个CIDR条目');
})();

View File

@@ -10,6 +10,7 @@ githubassets.com
bing.com
bing.cn
bing.net
bingapis.com
live.com
stackoverflow.com
wikipedia.org
@@ -25,4 +26,10 @@ fbcdn.net
segment.io
unpkg.com
jsdelivr.com
tv.apple.com
tv.apple.com
instagram.com
cdninstagram.com
reddit.com
redd.it
whatsapp.com
whatsapp.net