-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_os.py
24 lines (19 loc) · 922 Bytes
/
get_os.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Simple Script I wrote to fetch the OS versions on a list of hostnames. The script uses ssh to log into the unix boxes and wmi
# to get info on a Windows box.
import wmi
import paramiko
with open('C:\\Users\\jorodriguez\\Desktop\\hosts.txt', 'r') as hostname:
for computer in hostname:
try:
#gets OS version on Linux boxes
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(computer.strip(), username='joroadmin', password='foo')
stdin, stdout, stderr = client.exec_command('cat /etc/redhat-release')
OS = stdout.readlines()
print computer.strip(), "-", ''.join([item.rstrip('\n') for item in OS])
except:
#gets OS version on Windows boxes
c = wmi.WMI(computer.strip())
for win in c.Win32_OperatingSystem():
print computer.strip(), '-', win.Caption