zoukankan      html  css  js  c++  java
  • 获取host信息

    QT如果要进行网络编程首先需要在.pro”中添加如下代码:
    QT += network
    在头文件中包含相关头文件:
    #include <QHostInfo>
    #include <QNetworkInterface>
    QHostInfo类用于获得主机信息。示范代码如下:
     QString localHostName = QHostInfo::localHostName();
        QHostInfo hostInfo = QHostInfo::fromName(localHostName);
        QList<QHostAddress> list = hostInfo.addresses();
        if(!list.isEmpty())
        {
            QList<QHostAddress>::iterator i;
            for (i = list.begin();i != list.end();i++)
                QMessageBox::information(this,tr("提示"), (*i).toString());
        }
    QNetworkInterface类获得与网络接口相关的信息,具体实现代码如下:
     QString detail="";
        QList<QNetworkInterface> list=QNetworkInterface::allInterfaces();
        QList<QNetworkInterface>::iterator i;
        for (i = list.begin();i != list.end();i++)
        {
            QNetworkInterface interface=*i;
            detail=tr("设备:")+interface.name()+"
    ";
            detail=detail+tr("硬件地址:")+interface.hardwareAddress()+"
    ";
            QList<QNetworkAddressEntry> entryList=interface.addressEntries();
            QList<QNetworkAddressEntry>::iterator j;
            for (j = entryList.begin();j != entryList.end();j++)
            {
                QNetworkAddressEntry entry=*j;
                detail=detail+"	"+tr("IP 地址:")+entry.ip().toString()+"
    ";
                detail=detail+"	"+tr("子网掩码:")+entry.netmask().toString()+"
    ";
                detail=detail+"	"+tr("广播地址:")+entry.broadcast().toString()+"
    ";
            }
            QMessageBox::information(this,tr("Detail"),detail);
        }
  • 相关阅读:
    洛谷 P4707 重返现世
    多项式总结&多项式板子
    线性常系数齐次递推
    洛谷 P2791 幼儿园篮球题
    CF Gym 102028G Shortest Paths on Random Forests
    洛谷 P4705 玩游戏
    [NOI2018]冒泡排序
    PKUSC2019 改题记录
    PKUSC2019 没约记
    Codeforces Round #557 题解【更完了】
  • 原文地址:https://www.cnblogs.com/shichuan/p/4497925.html
Copyright © 2011-2022 走看看