I wrote this simple script to check whether some of the specific ports are open or not.
#!/bin/bash
prt=(8080,22,53)
for i in "${prt[@]}"
do
nc -vz 127.0.0.1 $i
if [ $? -eq 0 ]; then
echo "succeeded"
echo $i
break
else
echo "refused"
fi
done
It should loop through the list of ports and print the first open port and then break from the loop. Except 8080 all other ports are open in my system and should in theory output succeeded 22
. But instead of doing that this is the output its giving
nc: port number invalid: 8080,22,53
refused