-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicOsCmdParser.py
51 lines (47 loc) · 2.09 KB
/
basicOsCmdParser.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from subprocess import Popen, PIPE
class BasicOsCmdParser:
def hostnameFqdn(self):
p = Popen(['/bin/hostname', '-f'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
return output.decode("utf-8")[:-1]
def passwdInfo(self):
p = Popen(['/bin/cat', '/etc/passwd'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
output = output.decode("utf-8")[:-1].split('\n')
result = {}
for user in output:
parsedUser = user.split(':')
result[parsedUser[0]] = ({'username' : parsedUser[0],
'password' : parsedUser[1],
'uid' : parsedUser[2],
'gid' : parsedUser[3],
'user_info' : parsedUser[4],
'home' : parsedUser[5],
'shell' : parsedUser[6]})
return result
def shadowInfo(self):
p = Popen(['/bin/cat', '/etc/shadow'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
output = output.decode("utf-8")[:-1].split('\n')
result = {}
for user in output:
parsedUser = user.split(':')
result[parsedUser[0]] = ({'username' : parsedUser[0],
'password' : parsedUser[1],
'lastchanged' : parsedUser[2],
'min_day' : parsedUser[3],
'password_expire' : parsedUser[4],
'warn' : parsedUser[5],
'inactive' : parsedUser[6],
'account_expire' : parsedUser[7]})
return result
def nameserver(self):
p = Popen(['/bin/cat', '/etc/resolv.conf'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
output = output.decode("utf-8")[:-1].split('\n')
result = []
for ns in output:
if "nameserver" in ns:
parsedNs = ns.split(' ')
result.append(parsedNs[1])
return result