Nic*_*ick 1 drivers debian tcp udp
我在 bash(1) 手册页中注意到了这一点。是否有提供此接口的操作系统或某些内核模块?在我的 Debian 安装上尝试过,但这些设备不存在。
谢谢
/dev/tcp/host/port
If host is a valid hostname or Internet address, and port is an integer port number or service
name, bash attempts to open the corresponding TCP socket.
/dev/udp/host/port
If host is a valid hostname or Internet address, and port is an integer port number or service
name, bash attempts to open the corresponding UDP socket.
Run Code Online (Sandbox Code Playgroud)
解决方案/答案:这是有效的,它是外壳的一个功能。去测试:
$ nc -l -p 5555
echo Hello > /dev/tcp/localhost/5555
$ nc -l -p 5555
Hello
Run Code Online (Sandbox Code Playgroud)
很酷。
正如杰夫所说,这是一个由 Bash 实现的功能,而不是内核。它仅适用于 shell 脚本或 shell 的命令行;其他程序打不开/dev/tcp/...。
要将其实现为内核模块,您必须提供一个新的虚拟文件系统。
要查看实际效果,您可以将 Bash 与 netcat 结合使用。跑
nc -l -p 5555
Run Code Online (Sandbox Code Playgroud)
在一个终端中,然后
echo Hello > /dev/tcp/localhost/5555
Run Code Online (Sandbox Code Playgroud)
在另一个; 您将在运行的终端中看到“Hello” nc。
| 归档时间: |
|
| 查看次数: |
1100 次 |
| 最近记录: |