Use ss instead of lsof (#4518)

* Use ss instead of lsof for pihole status checks

Signed-off-by: DL6ER <dl6er@dl6er.de>

* Use ss FILTER instead of piping into bash

Signed-off-by: DL6ER <dl6er@dl6er.de>

* Use ss in debug log generation

Signed-off-by: DL6ER <dl6er@dl6er.de>

* Remove lsof from dependencies

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2022-01-05 17:41:46 +01:00
committed by GitHub
parent 7807a93e10
commit 5823f5e254
3 changed files with 21 additions and 23 deletions

14
pihole
View File

@@ -283,26 +283,29 @@ Options:
}
analyze_ports() {
local lv4 lv6 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
lv4="$(ss --ipv4 --listening --numeric --tcp --udp src :${port})"
if grep -q "udp " <<< "${lv4}"; then
echo -e " ${TICK} UDP (IPv4)"
else
echo -e " ${CROSS} UDP (IPv4)"
fi
if grep -q "IPv4.*TCP" <<< "${1}"; then
if grep -q "tcp " <<< "${lv4}"; then
echo -e " ${TICK} TCP (IPv4)"
else
echo -e " ${CROSS} TCP (IPv4)"
fi
if grep -q "IPv6.*UDP" <<< "${1}"; then
lv6="$(ss --ipv6 --listening --numeric --tcp --udp src :${port})"
if grep -q "udp " <<< "${lv6}"; then
echo -e " ${TICK} UDP (IPv6)"
else
echo -e " ${CROSS} UDP (IPv6)"
fi
if grep -q "IPv6.*TCP" <<< "${1}"; then
if grep -q "tcp " <<< "${lv6}"; then
echo -e " ${TICK} TCP (IPv6)"
else
echo -e " ${CROSS} TCP (IPv6)"
@@ -324,7 +327,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 +336,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