2015-10-02 39 views
1

有没有一种可能的方式来连接到bash的任何开放端口?即不调用任何外部命令。 :) 我想用bash连接到打开的端口而不使用nc或telnet,我将不胜感激有人可以帮助我。用bash连接到一个开放的端口

回答

2

它取决于壳;例如,bash使用I/O重定向来连接到任意的TCP和UDP套接字。从手册页:

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只有在您的文件系统实施某种套接字点播时才有效。

一个非常基本的HTTP客户端:

$ exec 3<>/dev/tcp/www.example.com/80 
$ echo "GET /" >&3 
$ cat <&3 
相关问题