获取客户端信息测试

Microsoft Windows [版本 10.0.19044.1766]
(c) Microsoft Corporation。保留所有权利。

(env) E:\pyAPP\Madking>pip install WMI
Collecting WMI
Downloading WMI-1.5.1-py2.py3-none-any.whl (28 kB)
Collecting pywin32
Downloading pywin32-305-cp310-cp310-win_amd64.whl (12.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.1/12.1 MB 3.8 MB/s eta 0:00:00
Installing collected packages: pywin32, WMI
Successfully installed WMI-1.5.1 pywin32-305

[notice] A new release of pip available: 22.2.2 -> 22.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

(env) E:\pyAPP\Madking>python manage.py shell
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import wmi
>>> wmi_obj = wmi.WMI()
>>> import win32com
>>> wmi_service_obj = win32com.client.Dispatch("WbemScripting.SWbemLocator")
>>> wmi_service_connector = self.wmi_service_obj.ConnectServer(".", "root\cimv2")
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'self' is not defined
>>> wmi_service_connector = wmi_service_obj.ConnectServer(".", "root\cimv2")
>>> wmi_obj.Win32_Processor()
[<_wmi_object: b'\\\\DESKTOP-UA9R50E\\root\\cimv2:Win32_Processor.DeviceID="CPU0"'>]
>>> cpu_list = wmi_obj.Win32_Processor()
>>> dir(cpu_list[0])
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '
__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_
ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_associated_classes', '_cached_associa
ted_classes', '_cached_methods', '_cached_properties', '_getAttributeNames', '_get_keys', '_instance_of', '_keys', '_methods', '_prop
erties', 'associated_classes', 'associators', 'derivation', 'id', 'is_association', 'keys', 'methods', 'ole_object', 'path', 'propert
ies', 'property_map', 'put', 'qualifiers', 'references', 'set', 'wmi_property']
>>> cpu=cpu_list[0]
>>> cpu.Name
'Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz'
>>> cpu.NumberofCores
6
>>> ram_collections = wmi_service_connector.ExecQuery("Select * from Win32_PhysicalMemory")

>>> for i in ram_collections:
... print(i.capacity)
...
8589934592
8589934592

>>> for i in ram_collections: ())
... print(i.Capacity,i.Caption,i.Manufacturer,i.SerialNumber,i.SerialNumber,i.DeviceLocator.strip()) ()) ()))
...
8589934592 物理内存 80AD000080AD 72D9F1A2 72D9F1A2 DIMM A
8589934592 物理内存 80AD000080AD 72D9F135 72D9F135 DIMM B
>>> ^A

 

posted @ 2022-12-06 09:49  侬侬发  阅读(399)  评论(0编辑  收藏  举报