问题
I used netcat in the following way
nc -l 3333 //for server
nc 127.0.0.1 3333 // for client
With this I am able to use it as a two way chatting system.
My question is, then why is there another option
-p ( -p source_port Specifies the source port nc should use, subject to privilege restrictions and availability.)
It works with -p option too. What is the difference between the two?
回答1:
A TCP connection consists of two TCP endpoints, each consisting of an IP address and a TCP port. The client usually chooses a random port, although you can force netstat
to use a given port using the -p
option.
Try:
adi@laps:~$ nc -l 3333 -p 4444
nc: cannot use -p and -l
adi@laps:~$ nc -l 3333 &
[1] 6025
adi@laps:~$ nc localhost 3333 -p 3333
nc: bind failed: Address already in use
来源:https://stackoverflow.com/questions/16196438/using-netcat-with-p-option