feat(脚本): 增加hysteria2端口跳跃

pull/1006/head
mack-a 2024-04-08 17:23:05 +08:00
parent 0530acb9d1
commit 5830e6bfb8
1 changed files with 42 additions and 28 deletions

View File

@ -2869,10 +2869,10 @@ hysteriaPortHopping() {
echoContent skyBlue "\n进度 1/1 : 端口跳跃"
echoContent red "\n=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "仅支持UDP"
echoContent yellow "仅支持Hysteria2"
echoContent yellow "端口跳跃的起始位置为30000"
echoContent yellow "端口跳跃的结束位置为60000"
echoContent yellow "可以在30000-60000范围中选一段"
echoContent yellow "端口跳跃的结束位置为40000"
echoContent yellow "可以在30000-40000范围中选一段"
echoContent yellow "建议1000个左右"
echoContent yellow "请输入端口跳跃的范围,例如[30000-31000]"
@ -2891,58 +2891,49 @@ hysteriaPortHopping() {
if [[ -z "${portStart}" || -z "${portEnd}" ]]; then
echoContent red " ---> 范围不合法"
hysteriaPortHopping
elif ((portStart < 30000 || portStart > 60000 || portEnd < 30000 || portEnd > 60000 || portEnd < portStart)); then
elif ((portStart < 30000 || portStart > 40000 || portEnd < 30000 || portEnd > 40000 || portEnd < portStart)); then
echoContent red " ---> 范围不合法"
hysteriaPortHopping
else
echoContent green "\n端口范围: ${hysteriaPortHoppingRange}\n"
# ip -4 addr show | awk '/inet /{print $NF ":" $2}' | awk '{print ""NR""":"$0}'
# read -r -p "请选择对应网卡:" selectInterface
# if ! ip -4 addr show | awk '/inet /{print $NF ":" $2}' | awk '{print ""NR""":"$0}' | grep -q "${selectInterface}:"; then
# echoContent red " ---> 选择错误"
# hysteriaPortHopping
# else
iptables -t nat -A PREROUTING -p udp --dport "${portStart}:${portEnd}" -m comment --comment "mack-a_portHopping" -j DNAT --to-destination :${hysteriaPort}
iptables -t nat -A PREROUTING -p udp --dport "${portStart}:${portEnd}" -m comment --comment "mack-a_hysteria2_portHopping" -j DNAT --to-destination :${hysteriaPort}
if iptables-save | grep -q "mack-a_portHopping"; then
if iptables-save | grep -q "mack-a_hysteria2_portHopping"; then
allowPort "${portStart}:${portEnd}" udp
echoContent green " ---> 端口跳跃添加成功"
else
echoContent red " ---> 端口跳跃添加失败"
fi
# fi
fi
fi
}
# 读取端口跳跃的配置
readHysteriaPortHopping() {
if [[ -n "${hysteriaPort}" ]]; then
# interfaceName=$(ip -4 addr show | awk '/inet /{print $NF ":" $2}' | awk '{print ""NR""":"$0}' | grep "${selectInterface}:" | awk -F "[:]" '{print $2}')
if iptables-save | grep -q "mack-a_portHopping"; then
if iptables-save | grep -q "mack-a_hysteria2_portHopping"; then
portHopping=
portHopping=$(iptables-save | grep "mack-a_portHopping" | cut -d " " -f 8)
portHopping=$(iptables-save | grep "mack-a_hysteria2_portHopping" | cut -d " " -f 8)
portHoppingStart=$(echo "${portHopping}" | cut -d ":" -f 1)
portHoppingEnd=$(echo "${portHopping}" | cut -d ":" -f 2)
fi
fi
}
# 删除hysteria 端口条约iptables规则
# 删除hysteria2 端口跳跃iptables规则
deleteHysteriaPortHoppingRules() {
iptables -t nat -L PREROUTING --line-numbers | grep "mack-a_portHopping" | awk '{print $1}' | while read -r line; do
iptables -t nat -L PREROUTING --line-numbers | grep "mack-a_hysteria2_portHopping" | awk '{print $1}' | while read -r line; do
iptables -t nat -D PREROUTING 1
done
}
# hysteria2端口跳跃菜单
hysteriaPortHoppingMenu() {
# 判断iptables是否存在
if ! find /usr/bin /usr/sbin | grep -q -w iptables; then
echoContent red " ---> 无法识别iptables工具无法使用端口跳跃退出安装"
exit 0
fi
readHysteriaConfig
readHysteriaPortHopping
echoContent skyBlue "\n进度 1/1 : 端口跳跃"
echoContent red "\n=============================================================="
@ -2958,7 +2949,11 @@ hysteriaPortHoppingMenu() {
echoContent green " ---> 删除成功"
fi
elif [[ "${selectPortHoppingStatus}" == "3" ]]; then
echoContent green " ---> 当前端口跳跃范围为: ${portHoppingStart}-${portHoppingEnd}"
if [[ -n "${portHoppingStart}" && -n "${portHoppingEnd}" ]]; then
echoContent green " ---> 当前端口跳跃范围为: ${portHoppingStart}-${portHoppingEnd}"
else
echoContent yellow " ---> 未设置端口跳跃"
fi
else
hysteriaPortHoppingMenu
fi
@ -4633,10 +4628,18 @@ EOF
elif [[ "${type}" == "hysteria" ]]; then
echoContent yellow " ---> Hysteria(TLS)"
local clashMetaPortContent="port: ${port}"
local multiPort=
local multiPortEncode
if echo "${port}" | grep -q "-"; then
clashMetaPortContent="ports: ${port}"
multiPort="mport=${port}&"
multiPortEncode="mport%3D${port}%26"
fi
echoContent green " hysteria2://${id}@${currentHost}:${port}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#${email}\n"
echoContent green " hysteria2://${id}@${currentHost}:${singBoxHysteria2Port}?${multiPort}peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#${email}\n"
cat <<EOF >>"/etc/v2ray-agent/subscribe_local/default/${user}"
hysteria2://${id}@${currentHost}:${port}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#${email}
hysteria2://${id}@${currentHost}:${singBoxHysteria2Port}?${multiPort}peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#${email}
EOF
echoContent yellow " ---> v2rayN(hysteria+TLS)"
echo "{\"server\": \"${currentHost}:${port}\",\"socks5\": { \"listen\": \"127.0.0.1:7798\", \"timeout\": 300},\"auth\":\"${id}\",\"tls\":{\"sni\":\"${currentHost}\"}}" | jq
@ -4645,7 +4648,7 @@ EOF
- name: "${email}"
type: hysteria2
server: ${currentHost}
port: ${port}
${clashMetaPortContent}
password: ${id}
alpn:
- h3
@ -4654,11 +4657,11 @@ EOF
down: "${hysteria2ClientDownloadSpeed} Mbps"
EOF
singBoxSubscribeLocalConfig=$(jq -r ". += [{\"tag\":\"${email}\",\"type\":\"hysteria2\",\"server\":\"${currentHost}\",\"server_port\":${port},\"up_mbps\":${hysteria2ClientUploadSpeed},\"down_mbps\":${hysteria2ClientDownloadSpeed},\"password\":\"${id}\",\"tls\":{\"enabled\":true,\"server_name\":\"${currentHost}\",\"alpn\":[\"h3\"]}}]" "/etc/v2ray-agent/subscribe_local/sing-box/${user}")
singBoxSubscribeLocalConfig=$(jq -r ". += [{\"tag\":\"${email}\",\"type\":\"hysteria2\",\"server\":\"${currentHost}\",\"server_port\":${singBoxHysteria2Port},\"up_mbps\":${hysteria2ClientUploadSpeed},\"down_mbps\":${hysteria2ClientDownloadSpeed},\"password\":\"${id}\",\"tls\":{\"enabled\":true,\"server_name\":\"${currentHost}\",\"alpn\":[\"h3\"]}}]" "/etc/v2ray-agent/subscribe_local/sing-box/${user}")
echo "${singBoxSubscribeLocalConfig}" | jq . >"/etc/v2ray-agent/subscribe_local/sing-box/${user}"
echoContent yellow " ---> 二维码 Hysteria2(TLS)"
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria2%3A%2F%2F${id}%40${currentHost}%3A${port}%3Fpeer%3D${currentHost}%26insecure%3D0%26sni%3D${currentHost}%26alpn%3Dh3%23${email}\n"
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria2%3A%2F%2F${id}%40${currentHost}%3A${singBoxHysteria2Port}%3F${multiPortEncode}peer%3D${currentHost}%26insecure%3D0%26sni%3D${currentHost}%26alpn%3Dh3%23${email}\n"
elif [[ "${type}" == "vlessReality" ]]; then
local realityServerName=${xrayVLESSRealityServerName}
@ -4797,6 +4800,7 @@ showAccounts() {
readInstallProtocolType
readConfigHostPathUUID
readSingBoxConfig
readHysteriaPortHopping
echo
echoContent skyBlue "\n进度 $1/${totalProgress} : 账号"
@ -4926,10 +4930,17 @@ showAccounts() {
if [[ "${coreInstallType}" == "1" ]]; then
path="${singBoxConfigPath}"
fi
local hysteria2DefaultPort=
if [[ -n "${portHoppingStart}" && -n "${portHoppingEnd}" ]]; then
hysteria2DefaultPort="${portHoppingStart}-${portHoppingEnd}"
else
hysteria2DefaultPort=${singBoxHysteria2Port}
fi
jq -r -c '.inbounds[]|.users[]' "${path}06_hysteria2_inbounds.json" | while read -r user; do
echoContent skyBlue "\n ---> 账号:$(echo "${user}" | jq -r .name)"
echo
defaultBase64Code hysteria "${singBoxHysteria2Port}" "$(echo "${user}" | jq -r .name)" "$(echo "${user}" | jq -r .password)"
defaultBase64Code hysteria "${hysteria2DefaultPort}" "$(echo "${user}" | jq -r .name)" "$(echo "${user}" | jq -r .password)"
done
fi
@ -8648,6 +8659,7 @@ manageHysteria() {
echoContent yellow "依赖第三方sing-box\n"
echoContent yellow "1.重新安装"
echoContent yellow "2.卸载"
echoContent yellow "3.端口跳跃管理"
hysteria2Status=true
else
echoContent yellow "依赖sing-box内核\n"
@ -8660,6 +8672,8 @@ manageHysteria() {
singBoxHysteria2Install
elif [[ "${installHysteria2Status}" == "2" && "${hysteria2Status}" == "true" ]]; then
unInstallSingBox hysteria2
elif [[ "${installHysteria2Status}" == "3" && "${hysteria2Status}" == "true" ]]; then
hysteriaPortHoppingMenu
fi
}
@ -8787,7 +8801,7 @@ menu() {
cd "$HOME" || exit
echoContent red "\n=============================================================="
echoContent green "作者mack-a"
echoContent green "当前版本v3.2.36"
echoContent green "当前版本v3.2.37"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c"
showInstallStatus