|
|
|
@ -2850,15 +2850,17 @@ check_binary_ports() {
|
|
|
|
|
# Check for listening ports using lsof
|
|
|
|
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
|
|
|
# Linux
|
|
|
|
|
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | cut -d':' -f2 | uniq)
|
|
|
|
|
# Append found ports to the ports variable, followed by a space
|
|
|
|
|
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | cut -d':' -f2 | uniq | tr '\n' ' ')
|
|
|
|
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
|
# macOS
|
|
|
|
|
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | awk -F'[:\.]+' '{print $(NF-1)}' | uniq)
|
|
|
|
|
# Append found ports to the ports variable, followed by a space
|
|
|
|
|
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | awk -F'[:\.]+' '{print $(NF-1)}' | uniq | tr '\n' ' ')
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Remove duplicate ports if any
|
|
|
|
|
ports=$(echo "$ports" | uniq)
|
|
|
|
|
# Remove trailing spaces and duplicate ports if any
|
|
|
|
|
ports=$(echo "$ports" | xargs | tr ' ' '\n' | uniq | tr '\n' ' ')
|
|
|
|
|
|
|
|
|
|
if [ -z "$ports" ]; then
|
|
|
|
|
echo "$binary_name is not listening on any ports."
|
|
|
|
|