From 99d978ffd1354520f50e44027e10e1b89f355541 Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:43:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 64 +++++----- shell/find_best_cdn_ip.sh | 241 ++++++++++++-------------------------- 2 files changed, 115 insertions(+), 190 deletions(-) diff --git a/install.sh b/install.sh index a13681e..032cfba 100644 --- a/install.sh +++ b/install.sh @@ -982,6 +982,7 @@ initV2RayConfig(){ "clients": [ { "id": "${uuidtcp}", + "add": "${add}", "flow":"xtls-rprx-origin", "email": "${domain}_VLESS_XTLS/TLS-origin_TCP" }, @@ -1038,7 +1039,6 @@ initV2RayConfig(){ { "id": "${uuidws}", "alterId": 1, - "add": "${add}", "level": 0, "email": "${domain}_vmess_ws" } @@ -1286,6 +1286,7 @@ EOF fi fi + # VLESS_TCP cat << EOF > /etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json { "inbounds":[ @@ -1296,6 +1297,7 @@ EOF "clients": [ { "id": "${uuidtcp}", + "add": "${add}", "flow":"xtls-rprx-origin", "email": "${domain}_VLESS_XTLS/TLS-origin_TCP" }, @@ -1555,7 +1557,7 @@ showAccounts(){ local tcp=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[0]` local tcpID=`echo ${tcp}|jq .settings.clients[0].id` local tcpEmail="`echo ${tcp}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" - + local CDNADD=`echo ${tcp}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` # XTLS Direct local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id` local tcpDirectEmail="`echo ${tcp}|jq .settings.clients[1].email|awk -F '["]' '{print $2}'`" @@ -1564,21 +1566,18 @@ showAccounts(){ # VLESS ws local vlessWS=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[3]` local vlessWSID=`echo ${vlessWS}|jq .settings.clients[0].id` - local vlessWSAdd=`echo ${vlessWS}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local vlessWSEmail="`echo ${vlessWS}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local vlessWSPath=`echo ${vlessWS}|jq .streamSettings.wsSettings.path` # Vmess ws local ws=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[1]` local wsID=`echo ${ws}|jq .settings.clients[0].id` - local wsAdd=`echo ${ws}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` # Vmess tcp local vmessTCP=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[2]` local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` - local vmessTCPAdd=`echo ${vmessTCP}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` @@ -1589,10 +1588,10 @@ showAccounts(){ echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-direct ===========================" defaultBase64Code vlesstcp ${tcpDirectEmail} "${tcpIDirect}" "${host}" ${add} echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================" - defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${wsAdd} + defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${CDNADD} echoContent skyBlue "\n================================ VMess WS TLS CDN ================================" - defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${wsAdd} + defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${CDNADD} echoContent skyBlue "\n================================= VMess TCP TLS =================================" defaultBase64Code vmesstcp ${vmessTCPEmail} "${vmessTCPID}" "${host}" "${vmessTCPath}" "${host}" @@ -1606,6 +1605,7 @@ showAccounts(){ local tcpID=`echo ${tcp}|jq .settings.clients[0].id` local tcpEmail="`echo ${tcp}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local CDNADD=`echo ${tcp}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` # XTLS Direct local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id` local tcpDirectEmail="`echo ${tcp}|jq .settings.clients[1].email|awk -F '["]' '{print $2}'`" @@ -1623,34 +1623,34 @@ showAccounts(){ # VLESS ws local vlessWS=`cat /etc/v2ray-agent/v2ray/conf/VLESS_WS_inbounds.json|jq .inbounds[0]` local vlessWSID=`echo ${vlessWS}|jq .settings.clients[0].id` - local vlessWSAdd=`echo ${vlessWS}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` + local vlessWSAdd=`echo ${tcp}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local vlessWSEmail="`echo ${vlessWS}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local vlessWSPath=`echo ${vlessWS}|jq .streamSettings.wsSettings.path` echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================" - defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${wsAdd} + defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${CDNADD} fi if [[ ! -z `echo ${customInstallType}|grep 2` ]] then - local ws=`cat /etc/v2ray-agent/v2ray/conf/VMess_TCP_inbounds.json|jq .inbounds[0]` - local wsID=`echo ${ws}|jq .settings.clients[0].id` - local wsAdd=`echo ${ws}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` - local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" - local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` + + local vmessTCP=`cat /etc/v2ray-agent/v2ray/conf/VMess_TCP_inbounds.json|jq .inbounds[0]` + local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` + local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` echoContent skyBlue "\n================================= VMess TCP TLS =================================" defaultBase64Code vmesstcp ${vmessTCPEmail} "${vmessTCPID}" "${host}" "${vmessTCPath}" "${host}" fi if [[ ! -z `echo ${customInstallType}|grep 3` ]] then - local vmessTCP=`cat /etc/v2ray-agent/v2ray/conf/VMess_WS_inbounds.json|jq .inbounds[0]` - local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` - local vmessTCPAdd=`echo ${vmessTCP}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` - local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" - local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` + + local ws=`cat /etc/v2ray-agent/v2ray/conf/VMess_WS_inbounds.json|jq .inbounds[1]` + local wsID=`echo ${ws}|jq .settings.clients[0].id` + local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` echoContent skyBlue "\n================================ VMess WS TLS CDN ================================" - defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${wsAdd} + defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${CDNADD} fi fi fi @@ -1754,9 +1754,20 @@ checkFail(){ # 修改V2Ray CDN节点 updateV2RayCDN(){ echoContent skyBlue "\n进度 $1/${totalProgress} : 修改CDN节点" - if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] && [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] then - local add=`cat /etc/v2ray-agent/v2ray/config.json|grep -v grep|grep add` + local configPath= + if [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + then + configPath="/etc/v2ray-agent/v2ray/config.json" + elif [[ -d "/etc/v2ray-agent/v2ray/conf" ]] && [[ -f "/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" ]] + then + configPath="/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" + else + echoContent red " ---> 未安装" + exit 0; + fi + local add=`cat ${configPath}|grep -v grep|grep add` if [[ ! -z ${add} ]] then echoContent red "==============================================================" @@ -1786,10 +1797,10 @@ updateV2RayCDN(){ add=`echo ${add}|awk -F '["]' '{print $4}'` if [[ ! -z ${add} ]] then - sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl /etc/v2ray-agent/v2ray/config.json` + sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl ${configPath}` fi - # sed -i "s/domain08.qiu4.ml1/domain08.qiu4.ml/g" `grep "domain08.qiu4.ml1" -rl /etc/v2ray-agent/v2ray/config.json` - if [[ `cat /etc/v2ray-agent/v2ray/config.json|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] + # sed -i "s/domain08.qiu4.ml1/domain08.qiu4.ml/g" `grep "domain08.qiu4.ml1" -rl ${configPath}` + if [[ `cat ${configPath}|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] then echoContent green " ---> V2Ray CDN修改成功" handleV2Ray stop @@ -2178,5 +2189,4 @@ checkSystem(){ } checkSystem -menu - +menu \ No newline at end of file diff --git a/shell/find_best_cdn_ip.sh b/shell/find_best_cdn_ip.sh index e6bbfff..0b62244 100755 --- a/shell/find_best_cdn_ip.sh +++ b/shell/find_best_cdn_ip.sh @@ -1,167 +1,82 @@ -#!/usr/bin/env bash -num=5 -ip=() -timeout=1000 -echoType='echo -e' -trap 'onCtrlC' INT -function onCtrlC () { - statisticalContent - exit; -} -# 计算 -statisticalContent(){ - if [[ ! -z `ls /tmp|grep -v grep|grep ping.log` ]] +echoContent skyBlue "\n进度 $1/${totalProgress} : 修改CDN节点" + if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] then - echoContent red "=============================================" - echoContent yellow '计算中--->' - # 排序计算 - echoContent red "排序规则:丢包率>波动>平均延迟,只展示最优的三十条" - echoContent red "依次展示为:[ ip 丢包率 最小延迟 平均延迟 最大延迟 波动 ]" - cat /tmp/ping.log|sort -t ' ' -k 2n -k 6n -k 4n|head -30 - echoContent red "=============================================" - fi + local configPath= + if [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + then + configPath="${configPath}" + elif [[ -d "/etc/v2ray-agent/v2ray/conf" ]] && [[ -f "/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" ]] + then + configPath="/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" + else + echoContent red " ---> 未安装" + exit 0; + fi + local add=`cat ${configPath}|grep -v grep|grep add` + if [[ ! -z ${add} ]] + then + echoContent red "==============================================================" + echoContent yellow "1.CNAME www.digitalocean.com" + echoContent yellow "2.CNAME amp.cloudflare.com" + echoContent yellow "3.CNAME domain08.qiu4.ml" + echoContent yellow "4.手动输入" + echoContent red "==============================================================" + read -p "请选择:" selectCDNType + case ${selectCDNType} in + 1) + setDomain="www.digitalocean.com" + ;; + 2) + setDomain="amp.cloudflare.com" + ;; + 3) + setDomain="domain08.qiu4.ml" + ;; + 4) + read -p "请输入想要自定义CDN IP或者域名:" setDomain + ;; + esac + if [[ ! -z ${setDomain} ]] + then + # v2ray + add=`echo ${add}|awk -F '["]' '{print $4}'` + if [[ ! -z ${add} ]] + then + sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl ${configPath}` + fi + # sed -i "s/domain08.qiu4.ml1/domain08.qiu4.ml/g" `grep "domain08.qiu4.ml1" -rl ${configPath}` + if [[ `cat ${configPath}|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] + then + echoContent green " ---> V2Ray CDN修改成功" + handleV2Ray stop + handleV2Ray start + else + echoContent red " ---> 修改V2Ray CDN失败" + fi -} -# echo工具类 -echoContent(){ - case $1 in - # 红色 - "red") - ${echoType} "\033[31m$2 \033[0m" - ;; - # 天蓝色 - "skyBlue") - ${echoType} "\033[36m$2 \033[0m" - ;; - # 绿色 - "green") - ${echoType} "\033[32m$2 \033[0m" - ;; - # 白色 - "white") - ${echoType} "\033[37m$2 \033[0m" - ;; - "magenta") - ${echoType} "\033[31m$2 \033[0m" - ;; - "skyBlue") - ${echoType} "\033[36m$2 \033[0m" - ;; - # 黄色 - "yellow") - ${echoType} "\033[33m$2 \033[0m" - ;; - esac -} -# 测试 -pingTool(){ - echo ''>/tmp/ping.log - echoContent red "=============================================" - echoContent green "默认测试为五次,超时为1000ms" - echoContent red "=============================================" - read -p "请输入单个ip测试次数【默认为5次】:" testNum - if [[ "$testNum" =~ ^[0-9]+$ ]] - then - num=${testNum} + # trojan + if [[ -d "/etc/v2ray-agent/trojan" ]] && [[ -f "/etc/v2ray-agent/trojan/config.json" ]] + then + add=`cat /etc/v2ray-agent/trojan/config.json|jq .websocket.add|awk -F '["]' '{print $2}'` + if [[ ! -z ${add} ]] + then + sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl /etc/v2ray-agent/trojan/config.json` + fi + fi + + if [[ `cat /etc/v2ray-agent/trojan/config.json|jq .websocket.add|awk -F '["]' '{print $2}'` = ${setDomain} ]] + then + echoContent green "\n ---> Trojan CDN修改成功" + handleTrojanGo stop + handleTrojanGo start + else + echoContent red " ---> 修改Trojan CDN失败" + fi + fi + else + echoContent red " ---> 未安装可用类型" + fi else - echoContent red '使用默认' + echoContent red " ---> 未安装" fi - echoContent yellow "一共${#ip[*]}个IP,每个ip测试${num}次,大约耗时`expr ${#ip[*]} \* ${num} / 60`分钟" - echoContent yellow "可以中途Ctrl+c,这样只会计算、统计已经记录下来的" - for ((i=0;i<${#ip[*]};i++)) - do - if [[ -z ${ip[$i]} ]] - then - continue; - fi - pingResult=`ping -c ${num} -W ${timeout} ${ip[$i]}` - packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[p][a][c][k][e][t][s][ ][r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` - roundTrip=`echo ${pingResult}|awk -F "[r][o][u][n][d][-][t][r][i][p]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'` - if [[ "${release}" = "ubuntu" ]] || [[ "${release}" = "debian" ]] || [[ "${release}" = "centos" ]] - then - packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` - roundTrip=`echo ${pingResult}|awk -F "[r][t][t]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'` - fi - - ## |awk -F "[/]" '{print $1$2$3}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}' - if [[ -z ${roundTrip} ]] - then - roundTrip="无" - fi - echo "ip:${ip[$i]},丢包率:${packetLoss}%,最小/平均/最大/波动:${roundTrip}" - echo "${ip[$i]} ${packetLoss} ${roundTrip}" >> /tmp/ping.log - done - statisticalContent -} -# 查找国家和地区 -findCountry(){ - if [[ -z `ls /tmp|grep -v grep|grep ips` ]] - then - echoContent red "缺少ip库,请联系作者。" - exit 0; - fi - echoContent red "=============================================" - cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}' - echoContent red "=============================================" - read -p "输入上述数字:" selectType - if [[ -z `cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}'|grep -v grep|grep ${selectType}` ]] - then - echoContent red '输入有误,请重新输入' - findCountry - fi - findIPList ${selectType} -} -# 查找ip -findIPList(){ - country=`cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}'|grep -v grep|grep ${selectType}|sort -t ':' -k 1n|head -1|awk -F "[:]" '{print $2}'` - # cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}'|grep -v grep|grep 1|sort -t ':' -k 1n|head -1|awk -F "[:]" '{print $2}' - echoContent red "=============================================" - cat /tmp/ips|grep -v grep|grep ${country}|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $1"-"$2}'|awk '{print "["NR"]"":"$0}' - read -p "请输入上述数字进行测试相应的ip段:" selectType - if [[ -z ${selectType} ]] - then - echoContent red '输入有误请重新输入!' - findIPList $1 - fi - echo ${country} - # cat /tmp/ips|grep -v grep|grep 中国移动|awk -F "[|]" '{print NR"-"$2}'|grep 174-|head -1 |awk -F "[|]" '{print $2}' - eval $(cat /tmp/ips|grep -v grep|grep ${country}|awk -F "[|]" '{print NR"-"$2}'|grep ${selectType}-|head -1|awk -F "[-]" '{print $2}'|awk '{split($0,serverNameList," ");for(i in serverNameList) print "ip["i"]="serverNameList[i]}') - pingTool -} -# 检查系统 -checkSystem(){ - if [[ "`uname`" = "Darwin" ]] - then - release="Darwin" - elif [[ ! -z `find /etc -name "redhat-release"` ]] || [[ ! -z `cat /proc/version | grep -i "centos" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "red hat" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "redhat" | grep -v grep ` ]] - then - release="centos" - elif [[ ! -z `cat /etc/issue | grep -i "ubuntu" | grep -v grep` ]] || [[ ! -z `cat /proc/version | grep -i "ubuntu" | grep -v grep` ]] - then - release="ubuntu" - elif [[ ! -z `cat /etc/issue | grep -i "debian" | grep -v grep` ]] || [[ ! -z `cat /proc/version | grep -i "debian" | grep -v grep` ]] - then - release="debian" - fi - if [[ -z ${release} ]] - then - echoContent red "本脚本不支持此系统,请将下方日志反馈给开发者" - cat /etc/issue - cat /proc/version - killSleep > /dev/null 2>&1 - exit 0; - fi -} -# 下载ip库 -downloadIPs(){ - if [[ -z `ls /tmp|grep -v grep|grep ips` ]] - then - echoContent yellow '开始下载ip库' - wget -q -P /tmp/ https://raw.githubusercontent.com/mack-a/v2ray-agent/dev/fodder/ips/ips - echoContent yellow '下载结束' - fi -} -downloadIPs -checkSystem -findCountry - + menu \ No newline at end of file