7 Replies - 7231 Views - Last Post: 25 May 2013 - 04:41 PM Rate Topic: -----

#1 pyr0b0y  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 22-February 09

Run a python script on a remote machine?

Posted 07 May 2013 - 02:37 PM

I've been researching ways to run a python script on a remote machine (on the local network). I've looked at a couple libraries and looked into paramiko. This is what I have so far:

import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
client.load_system_host_keys()
client.connect( 'computer_name', username='admin', password='admin' )



I saved the file and ran it in terminal, but it does not show me as ssh'd into the machine. Am I missing something?

Once it creates an SSH connection, I want to open a number of browsers using webbrowser()

I've looked for a while but cannot find any hard answer.

Is This A Good Question/Topic? 0
  • +

Replies To: Run a python script on a remote machine?

#2 pyr0b0y  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 22-February 09

Re: Run a python script on a remote machine?

Posted 07 May 2013 - 03:05 PM

This is what i want the script to do on 5 computers:

Open SSH Session on machine
   run a webbrowser() command
   run a webbrowser() command
   run a webbrowser() command
Close SSH Session


This post has been edited by pyr0b0y: 07 May 2013 - 03:05 PM

Was This Post Helpful? 0
  • +
  • -

#3 Skyla Blue  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 01-May 13

Re: Run a python script on a remote machine?

Posted 11 May 2013 - 03:25 PM

Why don't you try doing this with sockets? Then execute your command using subprocess?
Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Run a python script on a remote machine?

Posted 12 May 2013 - 06:56 PM

I'm curious, what are you trying to accomplish? Why do you want to do this?
Was This Post Helpful? 0
  • +
  • -

#5 pyr0b0y  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 22-February 09

Re: Run a python script on a remote machine?

Posted 13 May 2013 - 08:40 AM

Ultimately, I'm building a GUI with buttons, and when a button is pressed, it will run a python script. The python script will SSH into various remote machines on the local network and pull up different dashboards; more of just an automation script.
Was This Post Helpful? 0
  • +
  • -

#6 Python_4_President  Icon User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 321
  • Joined: 13-August 11

Re: Run a python script on a remote machine?

Posted 22 May 2013 - 10:42 PM

on a LAN, I might try broadcasting a message that clients listen for with pcapy.

I've done stuff like that in the past with good results, and also with serving a command that clients periodically check for.

These types of strategies are fun when testing cross-platform applications on a variety of virtual machines, or for wooing stupid sales people on a bigscreen showing a dozen VMs that all use web-driver to interact with the same webapp in a "this is the users will actually do it" sort of way.
Was This Post Helpful? 0
  • +
  • -

#7 trh51  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 20-May 12

Re: Run a python script on a remote machine?

Posted 24 May 2013 - 07:00 PM

Google it. It seems simpler to use the Command Prompt and a batch file than fiddling around with python. Other than that it would be easier to setup a simple socket server in python and have the machines connect to you to run the code. It seems really bot-net(ish) but there is a reason why they are so prevalent and it is because they work so well...

Simple socket server from http://ilab.cs.byu.e...echoserver.html:
import socket 

host = '' 
port = 50000 
backlog = 5 
size = 1024 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.bind((host,port)) 
s.listen(backlog) 
while 1: 
    client, address = s.accept() 
    client.send("start notepad")
    client.close()



Client software:(untested)
import socket
import os

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.connect((adress, port))    #Must input address and port, from above would be 5000
command = s.recv(1024)
s.close()
os.system(str(command))




Good luck, I'm not going to be running the second set of code on my machine because firewalls can only do so much...
Was This Post Helpful? 0
  • +
  • -

#8 pyr0b0y  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 22-February 09

Re: Run a python script on a remote machine?

Posted 25 May 2013 - 04:41 PM

It seems to be working fine running the above script. I wrote it in python because thats what im most comfortable with. I'm going to start rewriting it in java so it can be run off a Nexus 10. Haven't touched Java in years so this should be fun...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1