Advertisement
skip420

controlpcpy

Sep 11th, 2021
4,850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. #create controlpc.py with slave.py
  2. # python3 slave.py codes
  3.  
  4. ##create slave.py with python3 controlpc.py
  5. #import time
  6. #import socket
  7. #import sys
  8. #import os
  9.  
  10. # Initialize s to socket
  11. #s = socket.socket()
  12.  
  13. # Initialize the host
  14. #host = "127.0.0.1"
  15.  
  16. # Initialize the port
  17. #port = 8080
  18.  
  19. # bind the socket with port and host
  20. #s.connect((host, port))
  21.  
  22. #print("Connected to Server.")
  23.  
  24. # receive the command from master program
  25. #command = s.recv(1024)
  26. #command = command.decode()
  27.  
  28. # match the command and execute it on slave system
  29. #if command == "open":
  30. #   print("Command is :", command)
  31. #    s.send("Command received".encode())
  32.      
  33.     # you can give batch file as input here
  34. #    os.system('ls')
  35.  
  36.  
  37. import time
  38. import socket
  39. import sys
  40. import os
  41.  
  42. # Initialize s to socket
  43. s = socket.socket()
  44.  
  45. # Initialize the host
  46. host = socket.gethostname()
  47.  
  48. # Initialize the port
  49. port = 8080
  50.  
  51. # Bind the socket with port and host
  52. s.bind(('', port))
  53.  
  54. print("waiting for connections...")
  55.  
  56. # listening for connections
  57. s.listen()
  58.  
  59. # accepting the incoming connections
  60. conn, addr = s.accept()
  61.  
  62. print(addr, "is connected to server")
  63.  
  64. # take command as input
  65. command = input(str("Enter Command :"))
  66.  
  67. conn.send(command.encode())
  68.  
  69. print("Command has been sent successfully.")
  70.  
  71. # receive the confirmation
  72. data = conn.recv(1024)
  73.  
  74. if data:
  75.     print("command received and executed successfully.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement