Skip to content

Commit b462cb9

Browse files
committed
add dns set
1 parent e66d07f commit b462cb9

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Usage: xray [options]... [args]...
8787
web [name] [domain] 更改伪装网站
8888
8989
进阶:
90+
dns [...] 设置 DNS
9091
dd, ddel [name...] 删除多个配置**
9192
fix [name] 修复一个配置
9293
fix-all 修复全部配置

src/core.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ is_main_menu() {
16951695
show_help
16961696
;;
16971697
9)
1698-
ask list is_do_other "启用BBR 查看日志 查看错误日志 测试运行 重装脚本"
1698+
ask list is_do_other "启用BBR 查看日志 查看错误日志 测试运行 重装脚本 设置DNS"
16991699
case $REPLY in
17001700
1)
17011701
load bbr.sh
@@ -1713,6 +1713,10 @@ is_main_menu() {
17131713
5)
17141714
get reinstall
17151715
;;
1716+
6)
1717+
load dns.sh
1718+
dns_set
1719+
;;
17161720
esac
17171721
;;
17181722
10)
@@ -1786,6 +1790,10 @@ main() {
17861790
[[ $is_api_fail ]] && manage restart &
17871791
[[ $is_del_host ]] && manage restart caddy &
17881792
;;
1793+
dns)
1794+
load dns.sh
1795+
dns_set ${@:2}
1796+
;;
17891797
debug)
17901798
is_debug=1
17911799
get info $2

src/dns.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
is_dns_list=(
2+
1.1.1.1
3+
8.8.8.8
4+
https://dns.google/dns-query
5+
https://cloudflare-dns.com/dns-query
6+
https://family.cloudflare-dns.com/dns-query
7+
set
8+
none
9+
)
10+
dns_set() {
11+
if [[ $1 ]]; then
12+
case ${1,,} in
13+
11 | 1111)
14+
is_dns_use=${is_dns_list[0]}
15+
;;
16+
88 | 8888)
17+
is_dns_use=${is_dns_list[1]}
18+
;;
19+
gg | google)
20+
is_dns_use=${is_dns_list[2]}
21+
;;
22+
cf | cloudflare)
23+
is_dns_use=${is_dns_list[3]}
24+
;;
25+
nosex | family)
26+
is_dns_use=${is_dns_list[4]}
27+
;;
28+
set)
29+
if [[ $2 ]]; then
30+
is_dns_use=${2,,}
31+
else
32+
ask string is_dns_use "请输入 DNS: "
33+
fi
34+
;;
35+
none)
36+
is_dns_use=none
37+
;;
38+
*)
39+
err "无法识别 DNS 参数: $@"
40+
;;
41+
esac
42+
else
43+
is_tmp_list=(${is_dns_list[@]})
44+
ask list dns_pick
45+
is_dns_use=${is_dns_list[$REPLY - 1]}
46+
if [[ $is_dns_use == "set" ]]; then
47+
ask string is_dns_use "请输入 DNS: "
48+
fi
49+
fi
50+
is_new_dns=$(sed s/https/https+local/ <<<$is_dns_use)
51+
if [[ $is_new_dns == "none" ]]; then
52+
cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json
53+
else
54+
cat <<<$(jq '.dns.servers=["'$is_new_dns'"]' $is_config_json) >$is_config_json
55+
fi
56+
manage restart &
57+
msg "\n已更新 DNS 为: $(_green $is_new_dns)\n"
58+
}

src/help.sh

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ show_help() {
4040
" new [name] [...] 更改协议"
4141
" web [name] [domain] 更改伪装网站\n"
4242
"进阶:"
43+
" dns [...] 设置 DNS"
4344
" dd, ddel [name...] 删除多个配置**"
4445
" fix [name] 修复一个配置"
4546
" fix-all 修复全部配置"

xray.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
args=$@
4-
is_sh_ver=v1.18
4+
is_sh_ver=v1.19
55

66
. /etc/xray/sh/src/init.sh

0 commit comments

Comments
 (0)