python-在windows上实现数据采集

python-在windows上实现数据采集

1. python-在windows上实现数据采集

  • 运行脚本所需

    • 需要在windows端安装python3
  • 编写脚本

    #!/usr/bin/env python3
    # _*_ coding: utf-8 _*_
    # Author:shichao
    # File: .py
    
    import wmi
    import socket
    
    
    w = wmi.WMI()
    #import osimport socketw = wmi.WMI()
    
    # #获取电脑使用者信息for CS in w.Win32_ComputerSystem():
    for CS in w.Win32_ComputerSystem():
        #print(CS)
        print("电脑名称: %s" %CS.Caption)
        print("使用者: %s" %CS.UserName)
        print("制造商: %s" %CS.Manufacturer)
        print("系统信息: %s" %CS.SystemFamily)
        print("工作组: %s" %CS.Workgroup)
        print("机器型号: %s" %CS.model)
        print("")
    #获取操作系统信息for OS in w.Win32_OperatingSystem():
    for OS in w.Win32_OperatingSystem():
        #print(OS)
        print("操作系统: %s" %OS.Caption)
        print("语言版本: %s" %OS.MUILanguages)
        print("系统位数: %s" %OS.OSArchitecture)
        print("注册人: %s" %OS.RegisteredUser)
        print("系统驱动: %s" %OS.SystemDevice)
        print("系统目录: %s" %OS.SystemDirectory)
        print("")
    
    #获取电脑IP和MAC信息 for address in w.Win32_NetworkAdapterConfiguration(ServiceName = "e1dexpress"):
    for address in w.Win32_NetworkAdapterConfiguration(IPEnabled='TRUE'):
        print('电脑IP和MAC信息')
        print("IP地址: %s" % address.IPAddress[0])
        print("MAC地址: %s" % address.MACAddress)
        print("网络描述: %s" % address.Description)
        print("")
    
    #获取电脑CPU信息for processor in w.Win32_Processor():
    for processor in w.Win32_Processor():
        #print(processor)
        print("CPU型号: %s" % processor.Name.strip())
        print("CPU核数: %s" % processor.NumberOfCores)
        print("")
    #获取BIOS信息for BIOS in w.Win32_BIOS():
    for BIOS in w.Win32_BIOS():
        #print(BIOS)
        print("使用日期: %s" %BIOS.Description)
        print("主板型号: %s" %BIOS.SerialNumber)
        print("当前语言: %s" %BIOS.CurrentLanguage)
        print("")
    #获取内存信息for memModule in w.Win32_PhysicalMemory():
    for memModule in w.Win32_PhysicalMemory():
        totalMemSize = int(memModule.Capacity)
        print("内存厂商: %s" %memModule.Manufacturer)
        print("内存型号: %s" %memModule.PartNumber)
        print("内存大小: %.2fGB" %(totalMemSize/1024**3))
        print("")
    #获取磁盘信息for disk in w.Win32_DiskDrive():
    for disk in w.Win32_DiskDrive():
        diskSize = int(disk.size)
        print("磁盘名称: %s" %disk.Caption)
        print("硬盘型号: %s" %disk.Model)
        print("磁盘大小: %.2fGB" %(diskSize/1024**3))
    #获取显卡信息for xk in w.Win32_VideoController():
    for xk in w.Win32_VideoController():
        print("显卡名称: %s" %xk.name)
        print("")
    
    #获取计算机名称和IP hostname = socket.gethostname()ip = socket.gethostbyname(hostname)print("计算机名称: %s" %hostname)
    hostname = socket.gethostname()
    ip = socket.gethostbyname(hostname)
    print("计算机名称: %s" %hostname)
    print("IP地址: %s" %ip)
    
  • 运行结果

    PS C:\Users\admin\Desktop> python .\test.py
    电脑名称: DESKTOP-FEPL0PD
    使用者: None
    制造商: VMware, Inc.
    系统信息: None
    工作组: WORKGROUP
    机器型号: VMware7,1
    
    操作系统: Microsoft Windows 10 专业版
    语言版本: zh-CN
    系统位数: 64 位
    注册人: admin
    系统驱动: \Device\HarddiskVolume4
    系统目录: C:\WINDOWS\system32
    
    电脑IP和MAC信息
    IP地址: 172.16.128.98
    MAC地址: 00:0C:29:C1:3C:C3
    网络描述: Intel(R) 82574L Gigabit Network Connection
    
    电脑IP和MAC信息
    IP地址: 10.0.30.3
    MAC地址: 00:0C:29:C1:3C:CD
    网络描述: Intel(R) 82574L Gigabit Network Connection #2
    
    电脑IP和MAC信息
    IP地址: 192.168.18.1
    MAC地址: 00:50:56:C0:00:01
    网络描述: VMware Virtual Ethernet Adapter for VMnet1
    
    电脑IP和MAC信息
    IP地址: 192.168.176.1
    MAC地址: 00:50:56:C0:00:08
    网络描述: VMware Virtual Ethernet Adapter for VMnet8
    
    CPU型号: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
    CPU核数: 2
    
    CPU型号: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
    CPU核数: 2
    
    使用日期: VMW71.00V.18227214.B64.2106252220
    主板型号: VMware-56 4d 9a 3c 67 e6 70 fc-36 19 2c 97 6a c1 3c c3
    当前语言: None
    
    内存厂商: VMware Virtual RAM
    内存型号: VMW-8192MB
    内存大小: 8.00GB
    
    磁盘名称: VMware Virtual disk SCSI Disk Device
    硬盘型号: VMware Virtual disk SCSI Disk Device
    磁盘大小: 499.99GB
    磁盘名称: VMware Virtual disk SCSI Disk Device
    硬盘型号: VMware Virtual disk SCSI Disk Device
    磁盘大小: 50.00GB
    显卡名称: Microsoft Remote Display Adapter
    
    显卡名称: VMware SVGA 3D
    
    计算机名称: DESKTOP-FEPL0PD
    IP地址: 10.0.30.3
    
posted @ 2023-01-31 11:06  七月流星雨  阅读(386)  评论(0编辑  收藏  举报