NMAP (or other) continuous port scan until it returns open

nmapport-scanning

Is there a way with nmap or anything else to do a continuous port scan, say on port 22, until the service comes up and the port is coming back as open?

Kind of like you may have an infinite ping going, timing out, to see when a host comes back up…but with port scanning?

Best Answer

If you're on Linux, you can try a small script with netcat:

while true;do nc -zv 192.168.100.1 22;sleep 5;done

What this does is check if you can open a TCP connection to the SSH port every 5 seconds. If it does, you'll see this in the stdout:

Connection to 192.168.100.1 22 port [tcp/ssh] succeeded!