-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverinfo.py
executable file
·40 lines (36 loc) · 1.21 KB
/
serverinfo.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
'''
File name: serverinfo.py
Author: lhvphan
Email: lhvphan@gmail.com
Date created: April 3, 2022
Python Version: 3.8
Description: call system for various information, returns json object
'''
import json
import platform
import socket
import re
import uuid
import psutil
class ServerInfo:
def getsysteminfo(self):
"""
function getsysteminfo: get server information
:param self: self object
:return returnval: json object
"""
# get various system information
info={}
info['platform']=platform.system()
info['platform-release']=platform.release()
info['platform-version']=platform.version()
info['architecture']=platform.machine()
info['hostname']=socket.gethostname()
info['ip-address']=socket.gethostbyname(socket.gethostname())
info['mac-address']=':'.join(re.findall('..', '%012x' % uuid.getnode()))
info['processor']=platform.processor()
info['ram']=str(round(psutil.virtual_memory().total / (1024.0 **3)))+" GB"
# convert object to json object
returnval = json.dumps(info)
print("system information (json): %s" % returnval)
return returnval