有没有可能用bash连接到任何开放的端口?即不调用任何外部命令。 :) 我想使用bash连接到一个开放的端口,但不想使用nc或telnet。
这取决于使用的shell;例如,bash
使用I/O重定向来连接任意TCP和UDP套接字。从man页面上看:
Bash handles several filenames specially when they are used in redirections, as
described in the following table:
[...]
/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 a
TCP connection to the corresponding 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 a
UDP connection to the corresponding socket.
cat < /dev/tcp/time-a.nist.gov/13
cat /dev/tcp/time-a.nist.gov/13
才能正常工作。$ exec 3<>/dev/tcp/www.example.com/80
$ echo "GET /" >&3
$ cat <&3