diff options
Diffstat (limited to 'bin/ncp-diag')
-rw-r--r-- | bin/ncp-diag | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/bin/ncp-diag b/bin/ncp-diag index 4d2d0fc9..ef0d879c 100644 --- a/bin/ncp-diag +++ b/bin/ncp-diag @@ -64,11 +64,13 @@ echo "internet check|$( ping -W 2 -w 1 -q github.com &>/dev/null && echo ok || e function is_port_open() { - PORT=$1 - tmp_file=$(mktemp) - v=$(wget -T2 -t1 -q --keep-session-cookies --save-cookies $tmp_file https://portchecker.co -O - | grep -oP "_csrf\" value=\"\K.*\"") - wget -T2 -t1 -q --load-cookies $tmp_file https://portchecker.co --post-data "port=$PORT&_csrf=${v::-1}" -O - \ - | grep -q '<span class="green">open</span>' && { echo "open"; return 1; } + local PORT=$1 + local tmp_file=$(mktemp) + local v=$(wget -T2 -t1 -q --keep-session-cookies --save-cookies $tmp_file https://portchecker.co -O - | grep -oP "_csrf\" value=\"\K.*\"") + if [[ "$v" != "" ]]; then + wget -T2 -t1 -q --load-cookies $tmp_file https://portchecker.co --post-data "port=$PORT&_csrf=${v::-1}" -O - \ + | grep -q '<span class="green">open</span>' && { echo "open"; return 1; } + fi echo "closed" rm $tmp_file } |