linux - 将 netcat 与 -p 选项一起使用

标签 linux networking netcat

<分区>

我是这样使用netcat的

nc -l 3333    //for server

nc 127.0.0.1 3333  // for client

有了这个,我可以将它用作双向聊天系统。

我的问题是,那为什么还有另一种选择

-p ( -p source_port Specifies the source port nc should use, subject to privilege restrictions and availability.)

它也适用于 -p 选项。两者有什么区别?

最佳答案

TCP 连接由两个 TCP 端点组成,每个端点由一个 IP 地址和一个 TCP 端口组成。客户端通常选择一个随机端口,尽管您可以使用 -p 选项强制 netstat 使用给定端口。

尝试:

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

关于linux - 将 netcat 与 -p 选项一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16196438/

相关文章:

mysql - 用户无法远程连接MySQL

c# - 我可以将 TcpClient 从一台服务器传递到另一台服务器吗?

linux - 如何让netcat多次接收数据包?

linux - 在响应中返回某个字符后,如何关闭 netcat 连接?

linux - 在每一行中仅从文本文件中过滤出匹配的值

linux - 脚本 : Name a file with percentage 的完成百分比

linux - 定期执行并在收到信号时执行的功能是否可以成为关键区域?

c++ - Poco::Net 服务器和客户端 TCP 连接事件处理程序

无法执行 netcat

ruby-on-rails - Ruby 守护进程不会在系统启动时执行