标签:imp color strip() 技术 exce pre div listen out
一、三次握手和四次挥手
二、基于TCP开发一款远程CMD程序
#服务器 import socket import subprocess server = socket.socket() server.bind( (‘127.0.0.1‘,9000) ) server.listen(5) while True: conn,addr = server.accept() print(addr) while True: try: data = conn.recv(1024).decode(‘utf-8‘) print(data) if len(data) == 0: continue if data == ‘q‘: break obj = subprocess.Popen( data,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE ) msg = obj.stdout.read() error = obj.stderr.read() if msg: print(msg.decode(‘gbk‘)) conn.send(msg) else: print(error.decode(‘gbk‘)) conn.send(error) except Exception as e: print(e) break conn.close()
#客户端 import socket client = socket.socket() client.connect( (‘127.0.0.1‘,9000) ) while True: cmd = input(‘请输入命令‘).strip() client.send(cmd.encode(‘utf-8‘)) if cmd == ‘q‘: break data = client.recv(1024).decode(‘gbk‘) print(data)
标签:imp color strip() 技术 exce pre div listen out
原文地址:https://www.cnblogs.com/binyuanxiang/p/11695740.html