2

man page of the nc command has following information

-k Forces nc to stay listening for another connection after its current connection is completed. It is an error to use this option without the -l option.

But nc --help output has not any information regarding to -k option.

And when I try to capture packages like

nc -kl -i 86400 -p 44444 > nc_44444.dmp

I got following error

netcat: invalid option -- 'k'

So what is the problem ? Is there any option called as "-k"

My problem is I have to capture some data from network and sometimes client application could disconnect from server port and it could reconnect again. So I don't want to get problem about disconnect/reconnect events

  • # uname -a Linux 2.6.32-504.el6.x86_64 #1 SMP Tue Sep 16 01:56:35 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux – Murat Mar 31 '15 at 13:35
  • # cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.6 (Santiago) – Murat Mar 31 '15 at 13:39
  • Name : nc Arch : x86_64 Version : 1.84 Release : 22.el6 Size : 109 k Repo : installed From repo : RHELServer Summary : Reads and writes data across network connections using TCP or UDP URL : openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc – Murat Mar 31 '15 at 13:39
  • Please provide the full output from running nc -h. I suspect you're running busybox nc, which doesn't support -k. Regular nc has supported the -k option since at least 2001 source. – Mikel Mar 31 '15 at 15:00
  • Where "regular" means the OpenBSD version, that everybody these days seems to use, rather than nc110 from 1996. – Mikel Mar 31 '15 at 15:08
0

Presumably, your version of nc doesn't have the -k option. You could upgrade, or, as a workaround, run without -k in a loop.

2

It looks like you're not using the netcat command you think. ie, check the result of which nc. As for me (CentOS 6.6), it's /usr/bin/nc and -k option works. However, correct syntax would be:

nc -l -k -i 86400 localhost 44444 > nc_44444.dmp

If you can't make it work, consider using ncat which is part of nmap package. (there are many netcat implementations...)

0

I get the same error with GNU netcat 0.7.1. The flag is supported by the BSD version of nc.

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.