运行命令效果
在学习使用telnet的过程中,明显发现英文资料比中文资料靠谱。我在Linux(Kubuntu 20.04)下执行了以下命令
telnet stackoverflow.com 80
GET /questions HTTP/1.1
Host: stackoverflow.com
telnet stackoverflow.com 80
GET / HTTP/1.1
Host: stackoverflow.com
可以发现首先返回的报文是HTTP/1.1的,其次报出301永久移动。
然后我执行了以下命令
telnet stackoverflow.com 80
GET / HTTP/1.1
Host: stackoverflow.com
返回结果如下
bernard@aqua:~$ telnet stackoverflow.com 80
Trying 151.101.1.69...
GET / HTTP/1.1
Host: stackoverflow.comConnected to stackoverflow.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: stackoverflow.com
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 0
Connection closed by foreign host.
该网站拒绝响应了访问根目录的请求
最后我执行了以下命令
telnet baidu.com 80
GET / HTTP/1.1
Host: baidu.com
执行结果如下
bernard@aqua:~$ telnet baidu.com 80
Trying 220.181.38.251...
Connected to baidu.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: baidu.com
HTTP/1.1 200 OK
Date: Thu, 14 Oct 2021 14:36:08 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Fri, 15 Oct 2021 14:36:08 GMT
Connection: Keep-Alive
Content-Type: text/html
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
Connection closed by foreign host.
服务器正常返回了报文和HTML网页的头部。
后续工作
我使用了一台Linux机器,和局域网下的另一台Linux机器来完成telnet命令的测试。
[bernard@master ~]$ telnet www.baidu.com
Trying 14.215.177.38...
^C
[bernard@master ~]$ telnet -a -l root ry1
Trying 219.229.250.197...
telnet: connect to address 219.229.250.197: Connection refused
[bernard@master ~]$ telnet slave
Trying 192.168.0.3...
telnet: connect to address 192.168.0.3: Connection refused
|