这个硬件信息的获取需要使用到 network 模块

admin 2022年6月27日08:54:07评论23 views字数 1278阅读4分15秒阅读模式

这个硬件信息的获取需要使用到 network 模块

# 1. 在pro文件中添加 QT += network
# 需要用到的头文件#include // 计算机名#include // 用户名(获取家目录,删除其它字段只保留用户名)#include // 网卡信息

cout << "当前计算机名:" << QHostInfo::localHostName(); cout << "当前登陆用户:" << QStandardPaths::writableLocation(QStandardPaths::HomeLocation).section("/", -1, -1);
QList AddressList = QNetworkInterface::allAddresses(); foreach(QHostAddress address, AddressList){ if(address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress::Null && address != QHostAddress::LocalHost){ if (address.toString().contains("127.0.")){ continue; } cout << "当前IP地址:" << address.toString(); break; } }
// ---> 依次输出系统中每张网卡的详细信息 QString detail=""; QList list=QNetworkInterface::allInterfaces(); for(int i=0;i<list.count();i++)< span=""></list.count();i++)<> { QNetworkInterface interface=list.at(i); detail=detail+tr("设备:")+interface.name()+"n"; detail=detail+tr("硬件地址:")+interface.hardwareAddress()+"n"; QList entryList=interface.addressEntries(); for(int j=0;j<entrylist.count();j++)< span=""></entrylist.count();j++)<> { QNetworkAddressEntry entry=entryList.at(j); detail=detail+"t"+tr("IP 地址:")+entry.ip().toString()+"n"; detail=detail+"t"+tr("子网掩码:")+entry.netmask().toString()+"n"; detail=detail+"t"+tr("广播地址:")+entry.broadcast().toString()+"n"; } } QMessageBox::information(this,tr("Detail"),detail);


这个硬件信息的获取需要使用到 network 模块


原文始发于微信公众号(汇编语言):这个硬件信息的获取需要使用到 network 模块

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年6月27日08:54:07
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   这个硬件信息的获取需要使用到 network 模块https://cn-sec.com/archives/1145307.html

发表评论

匿名网友 填写信息