Continuously listen to tcp port via terminal

S4M11R picture S4M11R · Mar 7, 2016 · Viewed 29k times · Source

Is it possible to listen to a port continuously?

I listen for incoming tcp notifications with following command

sudo nc -l -p 999

But as soon as notification arrives I have to restart listen with same command. Is it possible to listen to port without having to restart command when notifications arrives until user decides to abort listen?

Answer

Nico Villanueva picture Nico Villanueva · May 26, 2017

Sorta outdated question, but came up first on my Google search.

In order for netcat not to shutdown as soon as the first connection is received, you can add the -k option.

From the man:

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

Src: https://superuser.com/a/708133/410908