3

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

Murat
  • 31
  • 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 : http://www.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
  • Debian (wheezy) defaults to providing nc from the package netcat-traditional, which has very few options and certainly nothing so newfangled as -k. Fortunately there is also netcat-openbsd, but it has to be installed manually. – Chris Davies Mar 31 '15 at 22:58
  • S O L V E D
    The consultant installed netcat so I uninstalled netcat and then nc was not working. So I also removed and reinstalled nc again.
    Now -k option is working now
    Thanks for your helps
    – Murat Apr 01 '15 at 10:03

3 Answers3

4

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...)

apaul
  • 3,378
1

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

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
lony
  • 111
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.

dhag
  • 15,736
  • 4
  • 55
  • 65