Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuously listen to tcp port via terminal

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?

like image 225
S4M11R Avatar asked Mar 07 '16 10:03

S4M11R


People also ask

How do I listen to a TCP port?

To find what is listening on a TCP/IP port, open a terminal and go to a shell command-line, and use lsof , a command that LiSts Open Files (TCP ports are considered a type of file in UNIX).

How do I start listening ports in Linux?

The best Linux command to open a port is using nc command. Open the terminal and type nc -l -p port number. The port will be opening on our Linux system.


1 Answers

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

like image 178
Nico Villanueva Avatar answered Oct 28 '22 16:10

Nico Villanueva