netcat to check open port

nc -z -v 10.0.0.1 8080

check couple of hosts for port opening

PORT=8080
IP_LIST="10.0.0.1 10.0.0.2 10.0.0.3"
TIMEOUT=3 # timeout in seconds
for ip in $IP_LIST; do
 echo -n "$ip:$PORT "
  timeout $TIMEOUT nc -z -v $ip $PORT >/dev/null 2>/dev/null && echo '- OK' || echo '- NOT OK'
done


  • No labels