Oct-02-2021, 05:56 PM
(This post was last modified: Oct-02-2021, 11:50 PM by throwaway34.)
So i want to get a real-time readout of commands executed on the server side of the two scripts, How would I do that without only limited output?
Server side:
Server side:
#!/usr/bin/env python3
import socket
import platform
import subprocess
import shlex
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(4096)
data2 = data.decode('utf-8')
z = subprocess.run(data2, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, capture_output=True)
z2 = z.stdout + z.stderr
try:
conn.sendall(z2)
except BrokenPipeError:
print('the connection was closed.')Client side:#!/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-->(Remote)Host:')
cmd2 = cmd.encode('utf-8')
try:
s.sendall(cmd2)
data = s.recv(4096)
data2 = data.decode('utf-8')
print(data2)
except BrokenPipeError:
print('The connection has been closed by the Host.')
