May-12-2021, 05:43 AM
(This post was last modified: May-12-2021, 05:46 AM by throwaway34.)
Hello, Ive Posted on here about this script before and I had made some progress but now I have ran aground once again and hopefully you can help me. For whatever reason on line 19 On the client script I have an Input() function which cuts off each command entered at the space separating them. I don't get any trace back so sorry I don't have anything to post.
client:
server:
client:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#!/usr/bin/env python3 import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if True : try : Host = input ( 'Remote Host:' ) port = 4444 s.connect((Host, port)) except ConnectionRefusedError: print ( 'connection refused.' ) s.close() exit() except socket.gaierror: print ( 'connection refused.' ) s.close() exit() while True : cmd = input ( 'Host-->(R)Host:' ) cmd2 = (cmd).encode( 'utf-8' ) try : s.sendall(cmd2) data = s.recv( 1060 ) data2 = data.decode( 'utf-8' ) print (data2) except BrokenPipeError: print ( 'The connection has been closed by the Host.' ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#!/usr/bin/env python3 import socket import platform import subprocess s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Host = platform.node() port = 4444 if True : try : s.bind((Host, port)) s.listen( 1 ) except OSError: print ( 'The script is already running.' ) s.close() exit() conn, addr = s.accept() while True : data = conn.recv( 10 ) data2 = data.decode( 'utf-8' ) z = subprocess.run(data2, shell = True , stdout = subprocess.PIPE, stderr = subprocess.PIPE) z2 = z.stdout + z.stderr try : conn.sendall(z2) except BrokenPipeError: print ( 'the connection was closed.' ) |