2015-10-02 63 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 
相關問題