add dns set

This commit is contained in:
233boy
2024-05-08 20:02:55 +08:00
parent 3af96ec0bc
commit d999705479
5 changed files with 70 additions and 2 deletions

View File

@@ -86,6 +86,7 @@ Usage: v2ray [options]... [args]...
web [name] [domain] 更改伪装网站
进阶:
dns [...] 设置 DNS
dd, ddel [name...] 删除多个配置**
fix [name] 修复一个配置
fix-all 修复全部配置

View File

@@ -1700,7 +1700,7 @@ is_main_menu() {
show_help
;;
9)
ask list is_do_other "启用BBR 查看日志 查看错误日志 测试运行 重装脚本"
ask list is_do_other "启用BBR 查看日志 查看错误日志 测试运行 重装脚本 设置DNS"
case $REPLY in
1)
load bbr.sh
@@ -1718,6 +1718,10 @@ is_main_menu() {
5)
get reinstall
;;
6)
load dns.sh
dns_set
;;
esac
;;
10)
@@ -1795,6 +1799,10 @@ main() {
[[ $is_api_fail ]] && manage restart &
[[ $is_del_host ]] && manage restart caddy &
;;
dns)
load dns.sh
dns_set ${@:2}
;;
debug)
is_debug=1
get info $2

58
src/dns.sh Normal file
View File

@@ -0,0 +1,58 @@
is_dns_list=(
1.1.1.1
8.8.8.8
https://dns.google/dns-query
https://cloudflare-dns.com/dns-query
https://family.cloudflare-dns.com/dns-query
set
none
)
dns_set() {
if [[ $1 ]]; then
case ${1,,} in
11 | 1111)
is_dns_use=${is_dns_list[0]}
;;
88 | 8888)
is_dns_use=${is_dns_list[1]}
;;
gg | google)
is_dns_use=${is_dns_list[2]}
;;
cf | cloudflare)
is_dns_use=${is_dns_list[3]}
;;
nosex | family)
is_dns_use=${is_dns_list[4]}
;;
set)
if [[ $2 ]]; then
is_dns_use=${2,,}
else
ask string is_dns_use "请输入 DNS: "
fi
;;
none)
is_dns_use=none
;;
*)
err "无法识别 DNS 参数: $@"
;;
esac
else
is_tmp_list=(${is_dns_list[@]})
ask list dns_pick
is_dns_use=${is_dns_list[$REPLY - 1]}
if [[ $is_dns_use == "set" ]]; then
ask string is_dns_use "请输入 DNS: "
fi
fi
is_new_dns=$(sed s/https/https+local/ <<<$is_dns_use)
if [[ $is_new_dns == "none" ]]; then
cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json
else
cat <<<$(jq '.dns.servers=["'$is_new_dns'"]' $is_config_json) >$is_config_json
fi
manage restart &
msg "\n已更新 DNS 为: $(_green $is_new_dns)\n"
}

View File

@@ -40,6 +40,7 @@ show_help() {
" new [name] [...] 更改协议"
" web [name] [domain] 更改伪装网站\n"
"进阶:"
" dns [...] 设置 DNS"
" dd, ddel [name...] 删除多个配置**"
" fix [name] 修复一个配置"
" fix-all 修复全部配置"

View File

@@ -1,6 +1,6 @@
#!/bin/bash
args=$@
is_sh_ver=v4.18
is_sh_ver=v4.19
. /etc/v2ray/sh/src/init.sh