QT查询主机信息IP协议类型及地址

#pragma execution_character_set("utf-8")
GetDoMainIpProcess::GetDoMainIpProcess(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::GetDoMainIpProcess)
{
    ui->setupUi(this);
    ui->lineEdit_Url->setText("www.126.com");
}

GetDoMainIpProcess::~GetDoMainIpProcess()
{
    delete ui;
}


//网络层协议
QString GetDoMainIpProcess::ProtocolTypeName(QAbstractSocket::NetworkLayerProtocol protocoltype)
{
    switch (protocoltype) {
    case QAbstractSocket::IPv4Protocol:

        return "IPv4 Proctocol";
    case QAbstractSocket::IPv6Protocol:
        return "IPv6 Protocol";
    case QAbstractSocket::AnyIPProtocol:
        return "Any IP Protocol";
    default:
        return "Unknown Network Layer Protocl";
    }



}


//获取IP地址列表
void GetDoMainIpProcess::LookupHostInfoFunc(const QHostInfo &host)
{
    QList addresslist=host.addresses();
    for(int i=0;iplainTextEdit_DomainIP->appendPlainText("协议类型"+ProtocolTypeName(host.protocol()));
        ui->plainTextEdit_DomainIP->appendPlainText("本地IP地址:"+host.toString());

    }
}

void GetDoMainIpProcess::on_pushButton_clearData_clicked()
{
    ui->plainTextEdit_DomainIP->clear();
}


void GetDoMainIpProcess::on_pushButton_doMainIp_clicked()
{
    //主机名称
    QString strhostname=ui->lineEdit_Url->text();
    ui->plainTextEdit_DomainIP->appendPlainText("你所查询的主机信息:"+strhostname);
    QHostInfo::lookupHost(strhostname,this,SLOT(LookupHostInfoFunc(QHostInfo)));
}

你可能感兴趣的:(Qt从0到1,qt,tcp/ip,开发语言,c++)