O'Reilly logo

Python Network Programming Cookbook - Second Edition by Dr. M. O. Faruque Sarker, Pradeeban Kathiravelu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

We can use the paramiko module to create a remote session to a Unix machine. Then, from this session, we can read the remote machine's /proc/cpuinfo file to extract the CPU information.

Listing 6.3 gives the code for printing a remote machine's CPU information, as follows:

 #!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 6 # This program is optimized for Python 3.5.2. # It may run on any other version with/without modifications. # To make it run on Python 2.7.x, needs some changes due to API differences. # Follow the comments inline to make the program work with Python 2. import argparse import getpass import paramiko RECV_BYTES = 4096 COMMAND = 'cat /proc/cpuinfo' def print_remote_cpu_info(hostname, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required