Python script How to show remote machine CPU information

Python script How to show remote machine CPU information


#!/usr/bin/env python

import argparse
import getpass
import paramiko
COMMAND = ‘cat /proc/cpuinfo’

def print_remote_cpu_info(hostname, port, username, password):
client = paramiko.Transport((hostname, port))
client.connect(username=username, password=password)
stdout_data = []
stderr_data = []
session = client.open_channel(kind=’session’)
while True:
if session.recv_ready():
if session.recv_stderr_ready():
if session.exit_status_ready():
print ‘exit status: ‘, session.recv_exit_status()
print ”.join(stdout_data)
print ”.join(stderr_data)


if __name__ == ‘__main__’:
parser = argparse.ArgumentParser(description=’Remote file copy’)
parser.add_argument(‘–host’, action=”store”, dest=”host”, default=’localhost’)
parser.add_argument(‘–port’, action=”store”, dest=”port”, default=22, type=int)
given_args = parser.parse_args()
hostname, port =, given_args.port
username = raw_input(“Enter the username:”)
password = getpass.getpass(“Enter password for %s: ” %username)
print_remote_cpu_info(hostname, port, username, password)


root@ubuntu:~/python# python
Enter the username:khoa
Enter password for khoa:
exit status: 0
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
stepping : 9
microcode : 0x1b
cpu MHz : 2893.434
cache size : 4096 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx f16c rdrand hypervisor lahf_lm epb fsgsbase smep xsaveopt dtherm ida arat pln pts
bugs :
bogomips : 5786.86
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>