We have a windows-based machine with enabled WinRM and a linux-based machine with enabled ssh. Need to create base class which have IP address property and child classes which will manage machines over ssh or WinRM with the following
• Power off/restart
• command line interface to execute command via ssh/powershell on remote machine
• Get Windows Defender parameters
• Get windows registry key
Three modules are created:
base_client.py
contains a base class for any inheriting clients. Implemented as an abstract class, it requires any inheriting classes to implement its methods. It has four abstract classes:log_in()
,execute_command()
,reboot()
, andshutdown()
.ssh_client.py
contains a class implementation of a SSH client. It uses external packageparamiko
for an SSH implementation in Python. The class is written as a context-manager, so it needs to be used like that in order to ensure that sessions are opened and closed properly.winrm_client.py
contains a class implementation of a WinRM client. It uses external packagepywinrm
for a WinRM implementation in Python. It is not written as a context-manager as closing of the sessions seems to be done automatically bypywinrm
NOTE: The SSH client was implemented by testing against a Ubuntu 18.04.5 LTS machine and the WinRM client - against a Windows 7 Ultimate 6.1.7601 SP 1 Build 7601 machine, so there could be differences in how the clients work against other versions/distributions of Linux and Windows. I have aimed to create the commands as generic as possible to ensure they'll run on any version of Linux/Windows.
It's recommended to create a python virtual environment using Python 3.7.9+ and install the dependencies in the file requirements.txt to ensure that all required packages are available. The projects uses two external packages: