@sunjiehao/zyhy-network 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +1 -1
- package/zyhy-private-split +71 -41
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# ZYHY-Network
|
|
2
2
|
|
|
3
|
-
当前版本:`V0.2.
|
|
3
|
+
当前版本:`V0.2.3`
|
|
4
4
|
|
|
5
5
|
让 Mac 同时使用公司网线和 `ZYHY-Private` Wi-Fi:普通网络走网线,OA、邮箱等内网地址自动走 Wi-Fi。
|
|
6
6
|
|
|
7
7
|
## 功能
|
|
8
8
|
|
|
9
9
|
- 仅在网线已连接且 Wi-Fi 为 `ZYHY-Private` 时启用分流
|
|
10
|
-
- 监听 macOS
|
|
10
|
+
- 监听 macOS 网络与系统代理变化并自动更新,不再每 5 秒轮询
|
|
11
11
|
- 默认每 300 秒低频校验一次,可修改间隔或关闭
|
|
12
12
|
- 支持 `zyhy-network refresh` 立即刷新 DNS、路由和分流配置
|
|
13
13
|
- GitHub 与 npm 安装提供相同的 `zyhy-network` 命令
|
|
@@ -53,4 +53,5 @@ zyhy-network uninstall # 卸载,保留配置
|
|
|
53
53
|
## 注意
|
|
54
54
|
|
|
55
55
|
- 网线和 `ZYHY-Private` Wi-Fi 需要同时连接;网络变化后会自动恢复分流
|
|
56
|
+
- 系统代理工具重启或切换后,会自动恢复内网域名的代理绕过项
|
|
56
57
|
- Chrome 若无法打开内网,请关闭“设置 → 隐私和安全 → 安全 → 使用安全 DNS”
|
package/package.json
CHANGED
package/zyhy-private-split
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
set -euo pipefail
|
|
18
18
|
|
|
19
19
|
LABEL="com.zyhy.network.split"
|
|
20
|
-
VERSION="0.2.
|
|
20
|
+
VERSION="0.2.3"
|
|
21
21
|
PLIST="/Library/LaunchDaemons/${LABEL}.plist"
|
|
22
22
|
RECONCILE_LABEL="${LABEL}.reconcile"
|
|
23
23
|
RECONCILE_PLIST="/Library/LaunchDaemons/${RECONCILE_LABEL}.plist"
|
|
@@ -317,7 +317,8 @@ http_proxy_keys() {
|
|
|
317
317
|
echo "State:/Network/Global/Proxies"
|
|
318
318
|
while IFS= read -r key; do
|
|
319
319
|
[[ -n "$key" ]] || continue
|
|
320
|
-
if echo "show ${key}" | scutil
|
|
320
|
+
if echo "show ${key}" | scutil \
|
|
321
|
+
| grep -Eq '(HTTPEnable|HTTPSEnable|SOCKSEnable|ProxyAutoConfigEnable) : 1'; then
|
|
321
322
|
printf '%s\n' "$key"
|
|
322
323
|
fi
|
|
323
324
|
done < <(echo "list State:/Network/Service/.*/Proxies" | scutil | awk -F'= ' '/subKey/{print $2}')
|
|
@@ -336,12 +337,11 @@ read_proxy_exceptions() {
|
|
|
336
337
|
'
|
|
337
338
|
}
|
|
338
339
|
|
|
339
|
-
|
|
340
|
+
write_proxy_exceptions_for_key() {
|
|
341
|
+
local key=$1
|
|
342
|
+
shift
|
|
340
343
|
local items=$*
|
|
341
|
-
|
|
342
|
-
[[ -n "$items" ]] || return 0
|
|
343
|
-
while IFS= read -r key; do
|
|
344
|
-
[[ -n "$key" ]] || continue
|
|
344
|
+
if [[ -n "$items" ]]; then
|
|
345
345
|
scutil >/dev/null <<EOF
|
|
346
346
|
open
|
|
347
347
|
d.init
|
|
@@ -350,7 +350,16 @@ d.add ExceptionsList * ${items}
|
|
|
350
350
|
set ${key}
|
|
351
351
|
quit
|
|
352
352
|
EOF
|
|
353
|
-
|
|
353
|
+
else
|
|
354
|
+
scutil >/dev/null <<EOF
|
|
355
|
+
open
|
|
356
|
+
d.init
|
|
357
|
+
get ${key}
|
|
358
|
+
d.remove ExceptionsList
|
|
359
|
+
set ${key}
|
|
360
|
+
quit
|
|
361
|
+
EOF
|
|
362
|
+
fi
|
|
354
363
|
}
|
|
355
364
|
|
|
356
365
|
list_has() {
|
|
@@ -364,51 +373,69 @@ list_has() {
|
|
|
364
373
|
}
|
|
365
374
|
|
|
366
375
|
ensure_proxy_exceptions() {
|
|
367
|
-
local -a
|
|
368
|
-
local x
|
|
369
|
-
while IFS= read -r x; do
|
|
370
|
-
[[ -n "$x" ]] && cur+=("$x")
|
|
371
|
-
done < <(read_proxy_exceptions "")
|
|
376
|
+
local -a want=()
|
|
377
|
+
local key x changed=0
|
|
372
378
|
while IFS= read -r x; do
|
|
373
379
|
[[ -n "$x" ]] && want+=("$x")
|
|
374
380
|
done < <(wanted_proxy_exceptions | awk 'NF && !seen[$0]++')
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
381
|
+
|
|
382
|
+
while IFS= read -r key; do
|
|
383
|
+
[[ -n "$key" ]] || continue
|
|
384
|
+
local -a cur=() merged=()
|
|
385
|
+
while IFS= read -r x; do
|
|
386
|
+
[[ -n "$x" ]] && cur+=("$x")
|
|
387
|
+
done < <(read_proxy_exceptions "$key")
|
|
388
|
+
if [[ ${#cur[@]} -gt 0 ]]; then
|
|
389
|
+
merged=("${cur[@]}")
|
|
390
|
+
fi
|
|
391
|
+
for x in "${want[@]}"; do
|
|
392
|
+
if [[ ${#cur[@]} -gt 0 ]] && list_has "$x" "${cur[@]}"; then
|
|
393
|
+
continue
|
|
394
|
+
fi
|
|
395
|
+
merged+=("$x")
|
|
396
|
+
done
|
|
397
|
+
if [[ ${#merged[@]} -eq ${#cur[@]} ]]; then
|
|
380
398
|
continue
|
|
381
399
|
fi
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
400
|
+
write_proxy_exceptions_for_key "$key" "${merged[@]}"
|
|
401
|
+
changed=1
|
|
402
|
+
done < <(http_proxy_keys | awk 'NF && !seen[$0]++')
|
|
403
|
+
|
|
404
|
+
if (( changed )); then
|
|
405
|
+
log "proxy bypass +${want[*]}"
|
|
386
406
|
fi
|
|
387
|
-
write_proxy_exceptions "${merged[*]}"
|
|
388
|
-
log "proxy bypass +${want[*]}"
|
|
389
407
|
}
|
|
390
408
|
|
|
391
409
|
remove_proxy_exceptions() {
|
|
392
|
-
local -a
|
|
393
|
-
local x
|
|
394
|
-
while IFS= read -r x; do
|
|
395
|
-
[[ -n "$x" ]] && cur+=("$x")
|
|
396
|
-
done < <(read_proxy_exceptions "")
|
|
397
|
-
[[ ${#cur[@]} -gt 0 ]] || return 0
|
|
410
|
+
local -a want=()
|
|
411
|
+
local key x changed=0
|
|
398
412
|
while IFS= read -r x; do
|
|
399
413
|
[[ -n "$x" ]] && want+=("$x")
|
|
400
414
|
done < <(wanted_proxy_exceptions)
|
|
401
|
-
|
|
402
|
-
|
|
415
|
+
|
|
416
|
+
while IFS= read -r key; do
|
|
417
|
+
[[ -n "$key" ]] || continue
|
|
418
|
+
local -a cur=() keep=()
|
|
419
|
+
while IFS= read -r x; do
|
|
420
|
+
[[ -n "$x" ]] && cur+=("$x")
|
|
421
|
+
done < <(read_proxy_exceptions "$key")
|
|
422
|
+
[[ ${#cur[@]} -gt 0 ]] || continue
|
|
423
|
+
for x in "${cur[@]}"; do
|
|
424
|
+
if [[ ${#want[@]} -gt 0 ]] && list_has "$x" "${want[@]}"; then
|
|
425
|
+
continue
|
|
426
|
+
fi
|
|
427
|
+
keep+=("$x")
|
|
428
|
+
done
|
|
429
|
+
if [[ ${#keep[@]} -eq ${#cur[@]} ]]; then
|
|
403
430
|
continue
|
|
404
431
|
fi
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
432
|
+
write_proxy_exceptions_for_key "$key" "${keep[@]}"
|
|
433
|
+
changed=1
|
|
434
|
+
done < <(http_proxy_keys | awk 'NF && !seen[$0]++')
|
|
435
|
+
|
|
436
|
+
if (( changed )); then
|
|
437
|
+
log "proxy bypass restored"
|
|
409
438
|
fi
|
|
410
|
-
write_proxy_exceptions "${keep[*]}"
|
|
411
|
-
log "proxy bypass restored"
|
|
412
439
|
}
|
|
413
440
|
|
|
414
441
|
drop_state_entry() {
|
|
@@ -506,6 +533,10 @@ cmd_apply_locked() {
|
|
|
506
533
|
return 0
|
|
507
534
|
fi
|
|
508
535
|
|
|
536
|
+
# Proxy apps can replace ExceptionsList without changing IP, gateway, or DNS.
|
|
537
|
+
# Repair it before the network-input fast path so proxy-only events are enough.
|
|
538
|
+
ensure_proxy_exceptions
|
|
539
|
+
|
|
509
540
|
local input_tmp
|
|
510
541
|
input_tmp=$(mktemp)
|
|
511
542
|
write_network_inputs "$input_tmp" "$eth" "$wifi" "$wifi_ip" "$wifi_gw" "$wifi_dns"
|
|
@@ -555,7 +586,6 @@ cmd_apply_locked() {
|
|
|
555
586
|
|
|
556
587
|
write_resolvers "$wifi_dns"
|
|
557
588
|
write_hosts_block "$hosts_body"
|
|
558
|
-
ensure_proxy_exceptions
|
|
559
589
|
|
|
560
590
|
local tmp state_changed=0
|
|
561
591
|
tmp=$(mktemp)
|
|
@@ -796,8 +826,8 @@ start_network_event_stream() {
|
|
|
796
826
|
exec 3>"$WATCH_COMMAND_FIFO"
|
|
797
827
|
exec 4<"$WATCH_EVENT_FIFO"
|
|
798
828
|
cat >&3 <<'EOF'
|
|
799
|
-
n.add ^State:/Network/(Global/(IPv4|DNS)|Interface/.*/(IPv4|Link|AirPort)|Service/.*/(DHCP|DNS|IPv4))$ pattern
|
|
800
|
-
n.add ^Setup:/Network/Service/.*/(DNS|IPv4)$ pattern
|
|
829
|
+
n.add ^State:/Network/(Global/(IPv4|DNS|Proxies)|Interface/.*/(IPv4|Link|AirPort)|Service/.*/(DHCP|DNS|IPv4|Proxies))$ pattern
|
|
830
|
+
n.add ^Setup:/Network/(Global/Proxies|Service/.*/(DNS|IPv4|Proxies))$ pattern
|
|
801
831
|
n.watch
|
|
802
832
|
EOF
|
|
803
833
|
}
|