From 1a8ac71543ec827e18bee632dd32e40a6fc21070 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Tue, 11 May 2021 08:13:19 -0600 Subject: ncp-web: fix port checking Signed-off-by: nachoparker --- bin/ncp-diag | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/ncp-diag b/bin/ncp-diag index ef0d879c..b7d65e26 100644 --- a/bin/ncp-diag +++ b/bin/ncp-diag @@ -64,15 +64,19 @@ echo "internet check|$( ping -W 2 -w 1 -q github.com &>/dev/null && echo ok || e function is_port_open() { - local PORT=$1 + local port=$1 + local public_ip + public_ip="$(curl icanhazip.com 2>/dev/null)" || { echo "closed"; return 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 - \ + local token=$(wget -T2 -t1 -qO- --keep-session-cookies --save-cookies $tmp_file https://portchecker.co | grep -oP "_csrf\" value=\"\K.*\"") + rm $tmp_file + + if [[ "${token}" != "" ]]; then + wget -T2 -t1 -qO- --load-cookies $tmp_file https://portchecker.co --post-data "target_ip=${public_ip}&port=${port}&_csrf=${token::-1}" \ | grep -q 'open' && { echo "open"; return 1; } fi echo "closed" - rm $tmp_file } echo "port check 80|$( is_port_open 80 )" -- cgit v1.2.3