At work, the infrastructure team is rolling out new VMs with RHEL7 installed as the base OS. This particular image comes with the nmap-ncat
version of Netcat and does not have NMap installed. We are precluded from installing anything on the machines.
Previously, we were using the GNU Netcat which have the -z
option to scan a remote host/port to check if it was open. Something like this:
nc -z -v -w 3 remote.host.name 1234
How can I achieve the same check with the new ncat
which does not have the -z
option on a system where I cannot install nmap
?
Bash allows you to connect to TCP and/or UDP ports by redirecting to special files:
So to test if you can connect to port 80 on www.example.com the following should work:
If the port is blocked you either get a "connection refused" message or a timeout.
Though Ncat does not yet support
-z
, you can get the same behavior with shell redirection:The connect timeout can be adjusted with the
-w
option.EDIT: Ncat 7.25BETA2 introduced the
-z
option which works as it does with GNU netcat, but only on single ports. If you need to scan port ranges, you should be using Nmap.Neither netcat, telnet nor nmap are needed. Bash is simpler, portable and more efficient.
Open check
Open/Closed Check
Port Range Check