A Python package to execute code remotely to multiple operating system platforms
Project description
rudder
rudder
is a Python package to run commands remotely on Windows, macOS or *nix systems using PowerShell Remoting/WinRM or SSH.
Getting Started
In order to use rudder you must make sure you have access and credentials to authenticate to a remote host.
Prerequisites
The following packages will be installed and are prerequisities for rudder:
paramiko
fire
pypsrp
NOTE: To use this on your remote Windows machines, you need to do the following:
- Run from an elevated PowerShell prompt
winrm quickconfig (type yes)
Enable-PSRemoting (type yes)
# Set start mode to automatic
Set-Service WinRM -StartMode Automatic
# Verify start mode and state - it should be running
Get-WmiObject -Class win32_service | Where-Object {$_.name -like "WinRM"}
- Additionally you may need to specify the allowed host to remote into systems:
# Trust hosts
Set-Item 'WSMan:localhost\client\trustedhosts' -value * -Force
NOTE: don't use the * for the value parameter in production - specify your Swimlane instance IP
# Verify trusted hosts configuration
Get-Item WSMan:\localhost\Client\TrustedHosts
- Additional Troubleshooting
#If you receive a timeout error or something like that, check and make sure that your remote Windows host network is set to Private and NOT public. You can change it using the following:
# Get Network Profile
Get-NetConnectionProfile
# if the NetworkCategory is set to Public then run the following to set it to Private
Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private
# try it again
Installing
Install this package using pip
:
pip3 install rudder
Or you can clone this repository and install locally:
git clone https://github.com/MSAdministrator/rudder.git
cd rudder
python3 setup.py install
Usage
Below contains two prime examples of using rudder on both Windows and a *nix system.
Whether you are wanting to run a command remotely on Windows or a *nix based system (e.g. CentOS, macOS, etc.) you first need to create a HostInfo
object. You do this by importing the HostInfo
class in your script like so:
from rudder import HostInfo
Windows HostInfo Object
You first need to provide the following information when instantiating a HostInfo
object for Windows systems:
from rudder import HostInfo
windows_host = '10.0.0.0'
windows_username = 'Administrator'
windows_pass = 'somepassword'
hostinfo = HostInfo().windows(
windows_host,
windows_username,
windows_pass
)
*Nix HostInfo Object
You first need to provide the following information when instantiating a HostInfo
object for *nix systems:
from rudder import HostInfo
nix_host = '10.0.0.0'
nix_username = 'root'
nix_pass = 'somepassword'
# Optionally you can provide the following parameters:
# ssh_key_path = '/Users/username/.ssh/id_rsa'
# port = '2222'
hostinfo = HostInfo().linux(
nix_host,
nix_username,
password=nix_pass
ssh_key_path=None,
port=22
)
Running Command Remotely on Windows
With rudder you can run either cmd
or powershell
commands remotely. Below are two examples of these methods:
from rudder import Rudder, HostInfo
windows_host = '10.0.0.0'
windows_username = 'Administrator'
windows_pass = 'somepassword'
hostinfo = HostInfo().windows(
windows_host,
windows_username,
windows_pass
)
conductor = Rudder().execute(hostinfo, 'powershell', 'Get-ChildItem -Path "C:\" -Recurse')
print(conductor)
conductor = Rudder().execute(hostinfo, 'cmd', 'dir')
print(conductor)
Running Command Remotely on *Nix
With rudder you can run commands remotely using SSH and whichever shell is avaialble on the remote system:
from rudder import Rudder, HostInfo
nix_host = '10.0.0.0'
nix_username = 'root'
nix_pass = 'somepassword'
hostinfo = HostInfo().linux(
nix_host,
nix_username,
password=nix_pass
)
conductor = Rudder().execute(hostinfo, 'ssh', 'ls -al')
print(conductor)
Built With
- carcass - Python packaging template
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning.
Authors
- MSAdministrator - Initial work - MSAdministrator
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.