~增加对ss命令的兼容以替代netstat命令

This commit is contained in:
juewuy
2026-07-29 10:42:38 +08:00
parent db8ba09663
commit d8941fb202
4 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ routing_mark=$((fwmark + 2))
[ -z "$dns_nameserver" ] && {
dns_nameserver='223.5.5.5, 1.2.4.8'
netstat -ntlup 2>/dev/null | grep -q '127.0.0.1:53' && dns_nameserver='127.0.0.1'
netstat -ntlup 2>/dev/null | grep -q '127.0.0.1:53' || ss -ntlup 2>/dev/null | grep -q '127.0.0.1:53' && dns_nameserver='127.0.0.1'
}
[ -z "$dns_fallback" ] && dns_fallback="1.1.1.1, 8.8.8.8"
[ -z "$dns_resolver" ] && dns_resolver="223.5.5.5, 2400:3200::1"
+8 -1
View File
@@ -592,10 +592,17 @@ testcommand() {
2)
line_break
echo "==========================================================="
netstat -ntulp | grep 53
if ckcmd netstat;then
netstat -ntulp | grep 53
elif ckcmd ss;then
ss -ntulp | grep 53
else
echo -e "Neither net-tools nor iproute2 is installed. Please install one of these packages and try again."
fi
echo
echo -e "$TOOLS_NETSTAT_HINT"
echo "==========================================================="
sleep 2
;;
3)
line_break
+8 -3
View File
@@ -1,13 +1,18 @@
#!/bin/sh
# Copyright (C) Juewuy
. "$CRASHDIR"/libs/check_cmd.sh
load_lang check_port
_get_netstat_cmd() {
local cmd=netstat
ckcmd ss && cmd=ss
case "$1" in
tcp) echo "netstat -ntl" ;;
udp) echo "netstat -nul" ;;
*) echo "netstat -ntul" ;;
tcp) echo "$cmd -ntl" ;;
udp) echo "$cmd -nul" ;;
*) echo "$cmd -ntul" ;;
esac
}
+1 -1
View File
@@ -95,7 +95,7 @@ set_dns_mod() {
;;
*)
if [ "$num" -ge 1 ] && [ "$num" -lt 65535 ]; then
if ckcmd netstat && netstat -ntul | grep -q ":$num "; then
if netstat -ntul 2>/dev/null | grep -q ":$num " || ss -ntul 2>/dev/null | grep -q ":$num "; then
dns_redir_port="$num"
setconfig dns_redir_port "$dns_redir_port"
common_success