-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
55 lines (48 loc) · 1.61 KB
/
Copy pathbasic.py
File metadata and controls
55 lines (48 loc) · 1.61 KB
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
52
53
54
55
import traceback
from .base import BasePlugin
from lib.response import BaseResponse
from lib.log import logger
class Basic(BasePlugin):
def os_platform(self, handler, hostname):
"""
获取系统平台
:param handler:
:param hostname:
:return:
"""
output = handler.cmd("uname", hostname)
return output.strip()
def os_version(self, handler, hostname):
"""获取系统版本"""
output = handler.cmd("cat /etc/issue", hostname)
result = output.strip().split("\n")[0]
return result
def os_hostname(self, handler, hostname):
"""获取主机名"""
output = handler.cmd("hostname", hostname)
return output.strip
def win(self, handler, hostname):
response = BaseResponse()
return response.dict
def linux(self, handler, hostname):
response = BaseResponse() # 相应对象
try:
if self.debug:
ret = {
"os_platform": "linux",
"os_version": "6.5",
"hostname": "c2.com"
}
else:
ret = {
"os_platform": self.os_platform(handler, hostname),
"os_version": self.os_version(handler, hostname),
"hostname": self.os_hostname(handler, hostname)
}
response.data = ret
except Exception as e:
msg = traceback.format_exc()
response.status = False
response.error = msg
logger.error(msg)
return response.dict