#include "networkinformation.h"
#include "ui_networkinformation.h"
networkinformation::networkinformation(QWidget *parent) :
QWidget(parent),
ui(new Ui::networkinformation)
{
ui->setupUi(this);
getHostInformation ();
connect (ui->detailBtn,SIGNAL(clicked()),this,SLOT(slotDetail()));
}
networkinformation::~networkinformation()
{
delete ui;
}
void networkinformation::getHostInformation ()
{
QString localHostName = QHostInfo::localHostName ();
ui->lineEditLocalHostName->setText(localHostName);
QHostInfo hostInfo = QHostInfo::fromName (localHostName);
QList<QHostAddress> listAddress = hostInfo.addresses ();
if(!listAddress.isEmpty ())
{
ui->lineEditAddress->setText(listAddress.first().toString());
}
}
void networkinformation::slotDetail ()
{
QString detail="";
QList<QNetworkInterface> list=QNetworkInterface::allInterfaces ();
for(int i=0;i<list.count();i++)
{
QNetworkInterface interface=list.at(i);
detail=detail+"equipment :"+interface.name()+"\n";
detail=detail+"hardware address :"+interface.hardwareAddress ()+"\n";
QList<QNetworkAddressEntry> entryList=interface.addressEntries ();
for(int j=0;j<entryList.count ();j++)
{
QNetworkAddressEntry entry=entryList.at(j);
detail=detail+"\t"+"IP Address :"+entry.ip ().toString ()+"\n";
detail=detail+"\t"+"subnet mask :"+entry.netmask().toString ()+"\n";
detail=detail+"\t"+"broadcast address :"+entry.broadcast ().toString ()+"\n";
}
}
QMessageBox::information (this,"detail",detail);
}