From edf08da6f38699675ac0271638558bce4cba5ecf Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 23 Mar 2016 22:23:24 +0800 Subject: [PATCH] compatible for netstat on FreeBSD --- le.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/le.sh b/le.sh index 9c5936c4..46f52ffa 100755 --- a/le.sh +++ b/le.sh @@ -181,21 +181,28 @@ _sign() { _ss() { _port="$1" - if command -v "netstat" >/dev/null 2>&1 ; then + + if _exists "ss" ; then + _debug "Using: ss" + ss -ntpl | grep :$_port" " + return 0 + fi + + if _exists "netstat" ; then _debug "Using: netstat" if netstat -h 2>&1 | grep "\-p proto" >/dev/null ; then #for windows version netstat tool netstat -anb -p tcp | grep "LISTENING" | grep :$_port" " else - netstat -ntpl | grep :$_port" " + if netstat -help 2>&1 | grep "-p protocol" >/dev/null ; then + netstat -an -p tcp | grep LISTEN | grep :$_port" " + else + netstat -ntpl | grep :$_port" " + fi fi return 0 fi - if command -v "ss" >/dev/null 2>&1 ; then - _debug "Using: ss" - ss -ntpl | grep :$_port" " - return 0 - fi + return 1 }