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?


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

while true;do nc -zv 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 22 port [tcp/ssh] succeeded!
| improve this answer | |
  • Perfect solution. And perfectly portable, looks like it should work on OSX as well. Thanks – TryTryAgain Sep 18 '15 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.