How to communicate between two windows machine and executing command on remote machine

I am working as an  Automation engineer and using Python and Robot framework to do my tasks in hand.Recently i had requirement in my project to make communication between two windows machines and execute command on remote machines. 

For Linux machines we have ssh client/Server software installed by default , in windows we don't have ssh.

I tried with  three options on windows

1)      Pywinrm – Unstable, bug prone. its a python library
2)      Winrm –  Its windows default functionality to communicate with other windows machine , looks bit complicated to use
3)      Paramiko  -one need to  install free SSH client software, however this has its own limitation when you are trying to configure it

After trying above , i came across with pstools  

Advantage

1)  This need not to be installed at remote desktop, so remote machine would be untouched
2)   it is super easy to use
3)   comes with lots of supportive tools like pslist,pskill to ease out the task

Lets see how one can start with it 

download the file from below URL and unzip it,add the path till Pstools folder in environment variable
https://docs.microsoft.com/en-us/sysinternals/downloads/pstools


open cmd type psexec , you will see lots of command line options.

Now coming to our scenarios 
window-window communication

Prerequisite  - 

1) check if both the devices are in same network .  if they are not , may be you can just turn your mobile hotspot on and connect both the laptops to your hotspot.
2) type ipconfig on both machines , if your connection is via LAN  , note down the IP address of Target machine


Communication and execuiting command on Target machine. 

we will use PsExec to do this task,By definition PsExec executes a program on a remote system

Format for communicating to a remote server and executing command there 

psexec \\Target/Remote Machine IP -u [username] -p[password]   command to be executed

See the example

. psexec \\192.168.43.127 -u INTRA\rechandr -p j2018  cmd /c ipconfig













 Reason to use cmd /c in above command

Thats because i want to run the ipconfig on cmd of remote machine , /c option closes the cmd after command is complete . on your terminal it wont have any sideeffect


This is way  by which you can execute a command on remote machine and get the output


List all the processes running on remote machines 

You can also list all the processes running on remote machines 

pslist \\192.168.1.20 -u INTRA\rechandr -p ja2018 cmd

this will list the cmd available on remote machine

Similarly you can kill the process with pskill 

command :
pskill \\192.168.43.127 -u rechandr -p jan@***2018  cmd


Comments

Popular posts from this blog

How to connect adb devices to linux container

How to start with APPIUM PYTHON

Configuring jenkins with Robot Framework