54 lines
1.2 KiB
Markdown
54 lines
1.2 KiB
Markdown
|
# Telnet 测试端口连通性
|
|||
|
|
|||
|
telnet命令是TELNET协议的用户接口,它支持两种模式:命令模式和会话模式,虽然telnet支持许多命令,但大部分情况下,我们只是使用它查看目标主机是否打开了某端口(默认是23)。
|
|||
|
|
|||
|
其执行结果有两种:
|
|||
|
|
|||
|
## 端口未打开
|
|||
|
|
|||
|
```bash
|
|||
|
telnet 101.199.97.65 62715
|
|||
|
Trying 101.199.97.65...
|
|||
|
telnet: connect to address 101.199.97.65: Connection refused
|
|||
|
```
|
|||
|
|
|||
|
此时,命令已退出。
|
|||
|
|
|||
|
## 端口已打开
|
|||
|
|
|||
|
```bash
|
|||
|
telnet 101.199.97.65 62715
|
|||
|
Trying 101.199.97.65...
|
|||
|
Connected to 101.199.97.65.
|
|||
|
Escape character is '^]'.
|
|||
|
```
|
|||
|
|
|||
|
此时命令未退出。
|
|||
|
|
|||
|
根据提示Escape character is '^]'.可知退出字符为'^]'(CTRL+])。此时输入其它字符不能使其退出,CTRL+C都不行。输入CTRL+]后会自动执行,进入命令模式:
|
|||
|
|
|||
|
```bash
|
|||
|
^]
|
|||
|
telnet>
|
|||
|
```
|
|||
|
|
|||
|
此时再运行 quit 才会真正退出。
|
|||
|
|
|||
|
```bash
|
|||
|
telnet> quit
|
|||
|
Connection closed.
|
|||
|
```
|
|||
|
|
|||
|
其中,Escape character 可以自定义,使用参数 -e:
|
|||
|
|
|||
|
```bash
|
|||
|
telnet -e p 101.199.97.65 62715 #使用p字符
|
|||
|
Telnet escape character is 'p'.
|
|||
|
Trying 101.199.97.65...
|
|||
|
Connected to 101.199.97.65.
|
|||
|
Escape character is 'p'.
|
|||
|
p
|
|||
|
telnet> quit
|
|||
|
Connection closed.
|
|||
|
```
|