lontokyo Posted January 26, 2021 Share Posted January 26, 2021 (edited) Selamlar herkese, Konu yanlis yerde acildiysa, moderatorlerden simdiden ozur dilerim, Sorum Server uzerinde kuruu sanal makineler de herhangi bir python script i uzaktan calistirmak ile alakali, script ve gerekli environment lari ayarladiktan sonra enduser'dan kullanici adi ve sifresini alarak, sanal makinede hazirda bekleyen scripti nasil calistirabilirim ? yardimlariniz icin simdiden tesekkurler Edited January 28, 2021 by lontokyo Cozumu eklendi Quote Link to comment Share on other sites More sharing options...
lontokyo Posted January 28, 2021 Author Share Posted January 28, 2021 yardimi olur diye bunu buraya birakmak istiyorum, # Server import socket import sys def socket_create(): try: global host global port global s host ="" port =9999 s = socket.socket() except socket.error as msg: print("Socket Creation error : " + str(msg)) def socket_bind(): try: global host global port global s print("Binding socket to port : " + str(port)) s.bind((host, port)) s.listen(5) except socket.error as msg: print("Socket binding error : " + str(msg) + "\n" + "Retrying") socket_bind() def socket_accept(): conn, address = s.accept() print("Connection has been established | " + "IP " + address[0] + " | Port " + str(address[1])) send_commands(conn) con.close() def send_commands(conn): while True: cmd = input() if cmd == 'quit': conn.close() sys.exit() if len(str.encode(cmd)) > 0: conn.send(str.encode(cmd)) client_response = str(conn.recv(1024), 'utf-8') print(client_response, end="") def main(): socket_create() socket_bind() socket_accept() main() #Client import os import socket import subprocess s = socket.socket() host = "" # server in ip adresini yaziniz port = 9999 s.connect((host, port)) while True: data = s.recv(1024) if data[:2].decode('utf-8') =='cd': os.chdir(data[3:].decode('utf-8')) if len(data)>0: cmd = subprocess.Popen(data[:].decode('utf-8'), shell=True, stdout=subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE) output_bytes = cmd.stdout.read() + cmd.stderr.read() output_str = str(output_bytes, 'utf-8') s.send(str.encode(output_str + str(os.getcwd()) + '> ')) print(output_str) 1 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.