telnet has default open port 23, which will remote login. But it has much more functions and can almost
fullfill any network service.
it'll help you learn network protocols and debug new developed ones.
1. use telnet to access web
telnet baidu.com 80
and use http protocol to access :
GET / HTTP/1.1
Host: baidu,com
and then you will get response
2. use telnet can access any network service:
here we implement a simple echo server and use telnet to access it
#! /usr/bin/python
from socket import *
import sys
host = ''
port = 50000
bufsize = 1024
addr = (host, port)
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(addr)
sock.listen(5)
try:
while True:
c_sock, addr = sock.accept()
data = c_sock.recv(bufsize)
if data:
print "receive data %s" %data
c_sock.send(data)
else:
break
c_sock.close()
sock.close()
except KeyboardInterrupt:
sock.close()
sys.exit()
open a terminal and start the echo server:bash-4.3> python echo_server.py
open another terminal and telnet it:
bash-4.3> telnet localhost 50000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
hello
Connection closed by foreign host.
final: to exit telnet session:
^] q
see man telnet

本文介绍如何使用Telnet访问Web服务及实现简单的网络服务交互。通过示例演示如何利用Telnet和HTTP协议获取网页内容,以及如何搭建并使用Telnet访问回显服务器。
4702

被折叠的 条评论
为什么被折叠?



