nc: invalid option -- 'z'
Asked Answered
R

3

19

On RHEL 7.2 OS, I get following error when trying to run nc commnad

nc -z -v -w1 host port
nc: invalid option -- 'z'
Ncat: Try `--help' or man(1) ncat for more information, usage options and help. QUITTING.

Is there any alternative to it

Rickety answered 1/8, 2016 at 9:40 Comment(3)
@fedorqui Presumably not. His question is how to work around the missing option.Blackbird
There are a lot of versions of nc/netcat around. In my system I have the Hobbit version with the -z, the OpenSSL without it, and the NMap witout it either.Recrudesce
@fedorqui. It does not show up under man ncRickety
P
6

maybe nc is a link to ncat, use the commands to check:

which nc | xargs ls -l

if the nc is linked to ncat,you should relink nc to netcat, if netcat is not installed, refer the website:http://netcat.sourceforge.net/download.php

Pulverize answered 4/1, 2018 at 12:42 Comment(0)
H
5

It seems the old version of nc is being phased out everywhere in favour of Nmap Ncat. Unfortunately this doesn't have the rather useful -z option.

One way to get equivalent functionality (test whether the target host is listening on a given port) is to transform this:

nc -z hostname port

Into this:

cat /dev/null | nc hostname port

You might also want to add in an option like -w 1s to avoid the long default timeout.

There might be a cleaner combination of options that avoids the need for the /dev/null but I couldn't figure out what.

I've also seen talk of using tcping to do the same thing, but that doesn't seem to be available on all distros.

Homogenize answered 13/9, 2018 at 8:25 Comment(0)
C
0

On the newer RHEL 7 nc is a link to ncat, while you may be used to nc on the older RHEL6 and below. ncat seems not to have the -z option, and being a different project having a look at it's man page is a good idea, or at least examine it's internal help

ncat -h
Charwoman answered 27/2, 2017 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.