Check port is open in shell

Moki Lv6
1
2
3
4
5
6
7
8
9
while read host port; do
r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
if [ "$r" = "0" ]; then
echo "$host $port is open"
else
echo "$host $port is closed"
exit 1
fi
done
On this page
Check port is open in shell