There are several tools you can use to verify access to a remote network port: nc, tcping, telnet. Unfortunately, nc from the netcat package has been replaced by the one from nmap, which lacks the -z option, making it useless for non-interactive applications.

A partial workaround with nc is to use the timeout flags:

Unfortunately, this method lends itself poorly to automation as on occasion it tends to hang and needs to be ran with the timeout commands and that adds another layer of complexity.

The tcping still works, but it’s an add-on package and it’s old, so some time soon it may disappear. The telnet is probably not going anywhere, but it’s also an add-on and not good for automated queries.

The answer is to use an all-Bash solution as shown below. In case you’re wondering about the sleep and kill stuff, it is possible that the cat command will time out due to a firewall that quietly drops connections.

 

Leave A Reply

Please enter your comment!
Please enter your name here