国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Python實(shí)現(xiàn)telnet服務(wù)器的方法

2020-01-04 18:05:45
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了Python實(shí)現(xiàn)telnet服務(wù)器的方法,涉及Python通過(guò)Telnet連接服務(wù)器的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)telnet服務(wù)器的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

 

 
  1. import threading  
  2. class myThread(threading.Thread): 
  3. def __init__(self,conn,add): 
  4. threading.Thread.__init__(self) 
  5. self.inputstr = '' 
  6. self.connection=conn 
  7. self.address=add 
  8. def run(self): 
  9. ii=0 
  10. while True: 
  11. self.connection.settimeout(50) 
  12. buf = self.connection.recv(1024) 
  13. if buf.rfind("/n") > -1 :  
  14. print "**-"+self.inputstr 
  15. self.connection.close()  
  16. break 
  17. else:  
  18. self.inputstr+=buf 
  19. if ii==0: 
  20. self.connection.send(buf) 
  21. ii+=1 
  22. continue 
  23. if __name__ == '__main__':  
  24. import socket  
  25. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  26. sock.bind(('192.168.101.103', 8014))  
  27. sock.listen(5) 
  28. while True:  
  29. try
  30. connection,address = sock.accept() 
  31. ithread=myThread(connection,address) 
  32. ithread.start() 
  33. except socket.timeout:  
  34. print 'time out' 

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 徐州市| 诏安县| 宽甸| 五台县| 九江市| 常熟市| 冷水江市| 邮箱| 龙陵县| 盐山县| 太仆寺旗| 陆河县| 亳州市| 梁山县| 南召县| 紫阳县| 武夷山市| 随州市| 保德县| 泌阳县| 乌鲁木齐县| 石景山区| 江安县| 清水县| 襄垣县| 萍乡市| 通河县| 聊城市| 林芝县| 定安县| 贵港市| 晋宁县| 白山市| 睢宁县| 临潭县| 溧水县| 克东县| 宁德市| 博白县| 泸西县| 惠东县|