telnet

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值