Python Forum
Remote control a machine via OS module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remote control a machine via OS module
#1
Hey, I made two python programs, in two different computers, that uses sockets to communicate between the two computers.
Then, I wanted to execute a terminal command at the client program and the command it self will be sent from the remote controller program, then the client will send the result back to the second program.
This is what I've tried:

The controller side:

import socket

s = socket.socket()
s.connect(('kali', 6655))

getInput = lambda: raw_input("client> ")

cmd = getInput()

while cmd != "###STOP###":
  s.send(cmd)
  reply = s.recv(1024)
  print("Output:\n\n{0}".format(reply))
  cmd = getInput()
s.send("###STOP###")
The Controlled side:

import socket
import os

s = socket.socket()
s.bind(('', 6655))
s.listen(1)

c, addr = s.accept()
print 'connected to: {0}'.format(addr)

cmd = ""
result = ""

getInput = lambda: c.recv(1024)
execute = lambda cmd: os.popen(cmd).read()

cmd = getInput()

while cmd != '###STOP###':
Those programs kinda work, it only worked for a few simple commands, for example: ls, pwd, cat, shutdown now. But when I tried more complex commands like: cd, rmdir, firefox. The program at the controlling side stopped working and I could not insert any input to send it to the controlled machine, it first executed those commands but afterwards, it was paused.

Does somebody know a different method that allows me to execute those commands or at least what's causing this problem?
Thanks in advance.
Reply


Messages In This Thread
Remote control a machine via OS module - by dindibo4 - Dec-15-2018, 05:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to gather information from remote host using ansible module in python amritjsr 0 2,046 Jul-20-2019, 01:17 AM
Last Post: amritjsr
  help need with running python script on remote windows machine onenessboy 2 11,131 Dec-14-2018, 03:02 PM
Last Post: onenessboy
  Remote control of the Visual Studio 2013 debug menu using Python MariusTo 0 2,479 Jan-17-2018, 04:58 PM
Last Post: MariusTo
  Possible to RDP onto a remote machine? jonesin1974 5 6,521 Dec-08-2017, 11:42 PM
Last Post: jonesin1974
  remote monitoring and control usb adapters Fran_3 0 2,285 Aug-24-2017, 07:55 PM
Last Post: Fran_3

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020