首页 > 代码库 > python shell
python shell
服务端:
1 import socket 2 def connect(): 3 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 4 s.bind((‘192.168.1.105‘, 8000)) 5 s.listen(1) 6 print ‘Listen on: 8000‘ 7 conn, addr = s.accept() 8 print ‘Conn from ‘, addr 9 10 while True: 11 cmd = raw_input(‘cmd>‘) 12 if ‘exit‘ in cmd: 13 conn.send(‘exit‘) 14 conn.close() 15 break 16 else: 17 conn.send(cmd) 18 print conn.recv(1024) 19 20 connect()
客户端:
1 import socket,subprocess 2 c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 3 c.connect((‘192.168.1.105‘,8000)) 4 while True: 5 cmd = c.recv(1024) 6 if ‘exit‘ in cmd: 7 c.close() 8 break 9 else: 10 cmd_ = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) 11 c.send(cmd_.stdout.read()) 12 c.send(cmd_.stderr.read())
python shell
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。