zoukankan      html  css  js  c++  java
  • QT获取本机IP和Mac地址

    #include <QNetworkInterface>
    #include <QList>
    
    void MainWindow::getIPPath()
    {
    
        QString strIpAddress;
    
        QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    
        // 获取第一个本主机的IPv4地址
    
        int nListSize = ipAddressesList.size();
    
        for (int i = 0; i < nListSize; ++i)
    
        {
    
            if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address())
            {
    
                strIpAddress = ipAddressesList.at(i).toString();
    
                break;
    
            }
    
        }
    
        // 如果没有找到,则以本地IP地址为IP
    
        if (strIpAddress.isEmpty())
        {
            qDebug() << strIpAddress;
            strIpAddress = QHostAddress(QHostAddress::LocalHost).toString();
        }
        qDebug() << "IP:" << strIpAddress;
    }
    
    void MainWindow::getMacPath()
    {
        QList<QNetworkInterface> nets = QNetworkInterface::allInterfaces();// 获取所有网络接口列表
    
        int nCnt = nets.count();
    
        QString strMacAddr = "";
    
        for(int i = 0; i < nCnt; i ++)
    
        {
    
            // 如果此网络接口被激活并且正在运行并且不是回环地址,则就是我们需要找的Mac地址
    
            if(nets[i].flags().testFlag(QNetworkInterface::IsUp) && nets[i].flags().testFlag(QNetworkInterface::IsRunning) && !nets[i].flags().testFlag(QNetworkInterface::IsLoopBack))
    
            {
    
                strMacAddr = nets[i].hardwareAddress();
    
                break;
    
            }
    
        }
        qDebug() << "Mac:" << strMacAddr;
    }
    

      

  • 相关阅读:
    HTB-靶机-Lazy
    HTB-靶机-Brainfuck
    HTB-靶机-October
    java编程思想-java注解
    HMAC的JAVA实现和应用
    HMACSHA1算法的JAVA实现
    常见软件安全漏洞样例代码
    [移动应用安全]移动应用安全培训PPT
    [标准性文档]WEB应用安全验证标准
    [安全测试报告]针对某厂商的一次渗透性测试
  • 原文地址:https://www.cnblogs.com/xupeidong/p/9494761.html
Copyright © 2011-2022 走看看