【PyQt4 实例18】获取网卡信息

来源:互联网 发布:手机网络信号不稳定 编辑:程序博客网 时间:2024/05/22 15:00
# -*- coding: utf-8 -*-from PyQt4.QtGui import *from PyQt4.QtCore import *import sysfrom PyQt4.QtNetwork import *QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))class LayoutDialog(QDialog):    def __init__(self,parent=None):        super(LayoutDialog,self).__init__(parent)        self.setWindowTitle(self.tr("本机信息"))        label1=QLabel(self.tr("主机名:"))        label2=QLabel(self.tr("IP地址:"))        userLineEdit=QLineEdit(self.tr("localhost"))        nameLineEdit=QLineEdit(self.tr("127.0.0.1"))        departmentTextEdit=QTextEdit()        ageLineEdit=QLineEdit()        labelCol=0        contentCol=1        leftLayout=QGridLayout()        leftLayout.addWidget(label1,0,labelCol)        leftLayout.addWidget(userLineEdit,0,contentCol)        leftLayout.addWidget(label2,1,labelCol)        leftLayout.addWidget(nameLineEdit,1,contentCol)        leftLayout.setColumnStretch(0,1)        leftLayout.setColumnStretch(1,3)        OKPushButton=QPushButton(self.tr("详细"))        leftLayout.addWidget(OKPushButton)        self.mainLayout=QGridLayout(self)        self.mainLayout.setMargin(15)        self.mainLayout.setSpacing(10)        self.mainLayout.addLayout(leftLayout,0,0)        self.mainLayout.setSizeConstraint(QLayout.SetFixedSize)                self.connect(OKPushButton,SIGNAL("clicked()"),self.slotButton)        def slotButton(self):        detail = QString()        list = QNetworkInterface.allInterfaces()        for i in xrange(len(list)):            interface = list[i]            detail = detail + self.tr("Device:") +interface.name() + "\n"            hardwareAddress = interface.hardwareAddress()            detail = detail + self.tr("HardwareAddress:") +interface.hardwareAddress() + "\n"            entryList = interface.addressEntries()            for j in xrange(len(entryList)):                entry= entryList[j]                detail = detail + "\t"+self.tr("IP Address:") +entry.ip().toString() + "\n"                detail = detail + "\t"+self.tr("Netmask:") +entry.netmask().toString() + "\n"                detail = detail + "\t"+self.tr("Broadcast:") +entry.broadcast().toString() + "\n"                    QMessageBox.information(self,self.tr("Detail"),detail)        app=QApplication(sys.argv)dialog=LayoutDialog()dialog.show()app.exec_()

0 0
原创粉丝点击