Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
First, we collect the connection parameters such as hostname, port, username, and password. These parameters are then passed to the print_remote_cpu_info() function.
This function creates an SSH client session by calling the transport class of paramiko. The connection is made thereafter using the supplied username and password. We can create a raw communication session using open_channel() on the SSH client. In order to execute a command on the remote host, exec_command() can be used.
After sending the command to the remote host, the response from the remote host can be caught by blocking the recv_ready() event of the session object. We can create two lists, stdout_data and stderr_data, and use them to store the remote output ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access