Using netcat with -p option [closed]

烈酒焚心 提交于 2019-12-13 04:32:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!