From 1721a1f4a9b76ea5bfa3727eebb3ee44e175b17f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 5 Jan 2022 06:17:03 +0100 Subject: [PATCH] Use netstat instead of lsof for pihole status checks Signed-off-by: DL6ER --- pihole | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pihole b/pihole index cd18b273..f996998c 100755 --- a/pihole +++ b/pihole @@ -283,26 +283,28 @@ Options: } analyze_ports() { + local listening port=${1} # FTL is listening at least on at least one port when this # function is getting called # Check individual address family/protocol combinations # For a healthy Pi-hole, they should all be up (nothing printed) - if grep -q "IPv4.*UDP" <<< "${1}"; then + listening="$(netstat --listening --numeric --tcp --udp | grep ":${port} ")" + if grep -q "udp " <<< "${listening}"; then echo -e " ${TICK} UDP (IPv4)" else echo -e " ${CROSS} UDP (IPv4)" fi - if grep -q "IPv4.*TCP" <<< "${1}"; then + if grep -q "tcp " <<< "${listening}"; then echo -e " ${TICK} TCP (IPv4)" else echo -e " ${CROSS} TCP (IPv4)" fi - if grep -q "IPv6.*UDP" <<< "${1}"; then + if grep -q "udp6 " <<< "${listening}"; then echo -e " ${TICK} UDP (IPv6)" else echo -e " ${CROSS} UDP (IPv6)" fi - if grep -q "IPv6.*TCP" <<< "${1}"; then + if grep -q "tcp6 " <<< "${listening}"; then echo -e " ${TICK} TCP (IPv6)" else echo -e " ${CROSS} TCP (IPv6)" @@ -324,7 +326,6 @@ statusFunc() { else #get the port pihole-FTL is listening on by using FTL's telnet API port="$(echo ">dns-port >quit" | nc 127.0.0.1 4711)" - listening="$(lsof -Pni:${port})" if [[ "${port}" == "0" ]]; then case "${1}" in "web") echo "-1";; @@ -334,7 +335,7 @@ statusFunc() { else if [[ "${1}" != "web" ]]; then echo -e " ${TICK} FTL is listening on port ${port}" - analyze_ports "${listening}" + analyze_ports "${port}" fi fi fi