I recently learned Python, using the relevant information about the machine, after some research, from the Internet to find information, after testing, summed up the relevant methods.
#-*-Coding:utf8-*-
Import OS
Import Win32API
Import datetime
Import Platform
Import Getpass
Import socket
Import UUID
Import _winreg
Import re
1. Read the registry to get the operating system version name
Def getosname ():
' Operating system name '
KeyPath = r "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
Each_key = _winreg. Openkey (_winreg. HKEY_LOCAL_MACHINE, KeyPath, 0, _winreg. Key_read)
OSNAME,REG_SZ = _winreg. QueryValueEx (Each_key, "ProductName")
Return Osname
2. Read the registry to get the current version number of the operating system
Def getosversion ():
"OS Version"
KeyPath = r "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
Each_key = _winreg. Openkey (_winreg. HKEY_LOCAL_MACHINE, KeyPath, 0, _winreg. Key_read)
OSVERSION,REG_SZ = _winreg. QueryValueEx (Each_key, "CurrentVersion")
Return OsVersion
3. Read the registry to get the model of the operating system
Def Getosmodel ():
"OS Model"
KeyPath = r "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
Each_key = _winreg. Openkey (_winreg. HKEY_LOCAL_MACHINE, KeyPath, 0, _winreg. Key_read)
OSMODEL,REG_SZ = _winreg. QueryValueEx (Each_key, "EditionID")
Return Osmodel
4.
#根据文件的全路径获取文件的版本号
def getfileversion (FilePath):
info = Win32API. GetFileVersionInfo (FilePath, OS.SEP)
ms = Info[' Fileversionms ')
ls = info[' fileversionls ')
Version = '%d.%d.%d.%0 4d '% (Win32API. HiWord (MS), Win32API. LoWord (MS), Win32API. HiWord (LS), Win32API. LoWord (LS))
return version
5. Read other information about the machine through the Platform module
Def get_architecture ():
"Get the number of operating system bits"
Return Platform.architecture ()
Def get_machine ():
' Computer type '
Return Platform.machine ()
Def get_node ():
"Network Name of the computer"
Return Platform.node ()
Def get_processor ():
"Computer processor Information"
Return Platform.processor ()
Def get_system ():
"Get OS Type"
Return Platform.system ()
Def get_totalinfo ():
"' Aggregated information '
Return Platform.uname ()
Def get_localdatapath ():
' Current user path '
return Os.path.expanduser (' ~ ')
Def get_username ():
"' Current user name '
Return Getpass.getuser ()
Def get_computername1 ():
"Get Machine name"
Return Platform.node () ()
Def get_computername ():
"Get Machine name"
Return Socket.gethostname ()
Def get_addressip ():
"Get native IP"
Return Socket.gethostbyname (Get_computername ())
Def get_mac ():
"Get MAC Address"
Mac=uuid. UUID (int = Uuid.getnode ()). HEX[-12:]
Return ': '. Join (Mac[e:e+2].upper () for E in xrange (0,11,2))
Def show_os_all_info ():
"Print all the information of the OS"
Print (' Number of bits of the operating system: [{}] '. Format (Get_architecture ()))
Print (' computer type: [{}] '. Format (Get_machine ()))
Print (' Network name for computer: [{}] '. Format (Get_node ()))
Print (' Computer processor information: [{}] '. Format (Get_processor ()))
Print (' OS type: [{}] '. Format (Get_system ()))
Print (' summary information: [{}] '. Format (Get_totalinfo ()))
Print (' Current user path: [{}] '. Format (Get_localdatapath ()))
Print (' Current user name: [{}] '. Format (Get_username ()))
Print (' machine name: [{}] '. Format (Get_computername ()))
Print (' machine IP: [{}] '. Format (Get_addressip ()))
Print (' Mac address: [{}] '. Format (Get_mac ()))
Python reads machine information