通过Python开发windows配置信息查看工具

效果图:


Python源代码如下:

# -*- coding:utf-8 -*-
from msilib import AMD64
import MySQLdb,time
import os,sys,platform,re,urllib2,socket,struct,time,uuid,wmi,zlib
reload(sys)
import subprocess
sys.setdefaultencoding('utf-8')


from Tkinter import *
root = Tk()


def get_mac_address():
#    mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
#    return ":".join([mac[e:e+2] for e in range(0,11,2)])
    c = wmi.WMI ()
    for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1):
        return interface.MACAddress


def cpu():
    c = wmi.WMI ()
    #CPU
    for processor in c.Win32_Processor():
        #print "Processor ID: %s" % processor.DeviceID
        cpu=processor.Name.strip()
        cpu=str(cpu)
        return cpu
def mem():
    c = wmi.WMI ()
    #内存
#    for Memory in c.Win32_PhysicalMemory():
#        sum=0
#        sum=sum+(int(Memory.Capacity)/1048576/1024)
#        return sum
#         return Memory
    sum=0
    for Memory in c.Win32_PhysicalMemory():
#        print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576)
        sum=sum+(int(Memory.Capacity)/1048576/1024)
    return sum




def disk():
    c = wmi.WMI ()
    #获取硬盘分区
    for physical_disk in c.Win32_DiskDrive ():
        for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
            for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
                print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8") , logical_disk.Caption


def disk1():
    c = wmi.WMI ()
    #获取硬盘分区
    for physical_disk in c.Win32_DiskDrive ():
        for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
            for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
                print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption


    #获取硬盘使用百分情况
    for disk in c.Win32_LogicalDisk (DriveType=3):
        print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))






def get_disk_info():
     """
     获取物理磁盘信息。
     """
     sum=0
     tmplist = []
     c = wmi.WMI ()
     for physical_disk in c.Win32_DiskDrive ():
         tmpdict = {}
         tmpdict["Caption"] = physical_disk.Caption
         tmpdict["Size"] = long(physical_disk.Size)/1024/1024/1024
         tmplist.append(tmpdict)
         num=len(tmplist)
     for i in range(0,num):
         sum=sum+tmplist[i]["Size"]
     return sum


def platform_info():
    i=platform.machine()
    if i == 'AMD64':
        return '64位操作系统'
    else:
        return '32位操作系统'


def motherboard():
    info=subprocess.Popen("wmic BaseBoard get Product", stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
    a=info.stdout.read().splitlines()
    return a[2]


def display():
    return "集成显卡"

Label(root,text = '电脑基本配置信息如下:',anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '现在时间:%s'%(time.strftime( '%Y-%m-%d %X', time.localtime())),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '操作系统:%s'%(platform.platform()),anchor = 'w',width = 60,height = 1).pack()
#Label(root,text = '计算机类型:%s'%(platform.machine()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '计算机类型:%s'%(platform_info()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '计算机名称:%s'%(platform.node()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '主板型号:%s'%(motherboard()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '计算机IP地址:%s'%(socket.gethostbyname_ex(socket.gethostname())[2][0]),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '计算机网卡MAC地址:%s' %(get_mac_address()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '计算机CPU类型:%s'%(cpu()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '计算机内存容量:%sG'%(mem()),anchor = 'w',width = 60,height = 1).pack()
#Label(root,text = '计算机内存容量:%sG'%(getRAMinfo())).pack()
Label(root,text = '计算机硬盘容量:%sG'%(get_disk_info()),anchor = 'w',width = 60,height = 1).pack()
Label(root,text = '显卡类型:%s'%(display()),anchor = 'w',width = 60,height = 1).pack()
root.title('System Monitor Design By 阮胜昌')
root.mainloop()






YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS