Python实现telnet服务器 Python实现telnet服务器的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python实现telnet服务器 Python实现telnet服务器的方法

Sephiroth   2021-03-21 我要评论
想了解Python实现telnet服务器的方法的相关内容吗,Sephiroth在本文为您仔细讲解Python实现telnet服务器的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Python,telnet,服务器,下面大家一起来学习吧。

本文实例讲述了Python实现telnet服务器的方法。分享给大家供大家参考。具体实现方法如下:

import threading 
class myThread(threading.Thread):
  def __init__(self,conn,add):
    threading.Thread.__init__(self)
    self.inputstr = ''
  self.connection=conn
  self.address=add
  def run(self):
  ii=0
    while True:
    self.connection.settimeout(50)
      buf = self.connection.recv(1024)
    if buf.rfind("\n") > -1 : 
        print "**-"+self.inputstr
        self.connection.close() 
        break
      else: 
        self.inputstr+=buf
    if ii==0:
      self.connection.send(buf)
    ii+=1
        continue
if __name__ == '__main__': 
  import socket 
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.bind(('192.168.101.103', 8014)) 
  sock.listen(5)
  while True: 
    try:
      connection,address = sock.accept()
      ithread=myThread(connection,address)
      ithread.start()
    except socket.timeout: 
      print 'time out'

希望本文所述对大家的Python程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们