Skip to content

Instantly share code, notes, and snippets.

@hexiyou
Last active February 2, 2024 12:17
Show Gist options
  • Save hexiyou/fa45fc193b06c61e7d923d633c1fdbdd to your computer and use it in GitHub Desktop.
Save hexiyou/fa45fc193b06c61e7d923d633c1fdbdd to your computer and use it in GitHub Desktop.
通用函数trojanports:Cygwin或Msys2一键查询trojan-qt5的监听端口号,并且探测端口类型!
trojanports() {
## 读取 Trojan-qt5.exe 代理端口配置;
## See Also:"D:\Extra\Trojan-Qt5-Windows-1.4.0\config.json"
print_color 40 "通过 netstat 命令获取 trojan-qt5.exe 端口监听信息..."
local pid=$(ps2 trojan-qt5.exe --nopath|dos2unix -q|awk -F '=' '/ProcessId=/{print $2;exit}')
[ -z "$pid" ] && print_color 9 "没有发现 trojan-qt5.exe 进程!" && return
local portsInfo=$(netstat -ano|grep $pid|dos2unix -q|awk -F " " '{if(match($2,/0.0.0.0:/) && $4=="LISTENING") print;}'|tee /dev/tty)
local portsInfo=$(echo "$portsInfo"|awk -F " " '{sub("0.0.0.0","127.0.0.1",$2);print}')
print_color 40 "探测各个端口类型..."
while read line
do
#echo "$line--"
local proxyAddr=$(echo "$line"|cut -d' ' -f2)
local testCount=0
while :;
do
[[ "$testAddr" != "" && "$testAddr" =~ ^socks5:// ]] && local testAddr="http://$proxyAddr" || local testAddr="socks5://$proxyAddr"
curl -s --connect-timeout 3 -x "$testAddr" https://www.baidu.com &>/dev/null
local curlRet=$?
#[ $curlRet -eq 0 ] && {
[ $curlRet -eq 0 -o $curlRet -eq 56 ] && {
print_color 70 "$proxyAddr 采用以下方式调用:"
[ $curlRet -eq 56 ] && print_color 40 "【提示】:该端口可能是PAC代理端口..."
cat <<EOF
export http_proxy=$testAddr
export https_proxy=$testAddr
export all_proxy=$testAddr
---
setallproxy ${testAddr/http:\/\//}
EOF
break
}
let testCount+=1
[ $testCount -ge 2 ] && break
done
unset testAddr
done <<<"$portsInfo"
}
@hexiyou
Copy link
Author

hexiyou commented Feb 2, 2024

使用效果截图:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment