Use netstat instead of lsof for pihole status checks

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2022-01-05 06:17:03 +01:00
parent 7807a93e10
commit 1721a1f4a9

13
pihole
View File

@@ -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