如题 , 通过QProcess获取到的局域网mac地址,使用QNetworkReply (记得要QT += network)可以获取其对应的生产产商(将mac地址传入某专门查询mac地址厂商的网站,并分析其返回值,获得结果,这个URL可以修改成别的,可以自己去调试),代码如下(从项目中摘取,放心使用):
//search mac with http for manufacturer; 需要联网;QString manufacturer = UNKOWN;if(mac!=UNKOWN && mac!="ipconfig -all"){QNetworkRequest request(QUrl("http://7n4.cn/?mac="+mac));request.setRawHeader("Host","7n4.cn");request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");request.setRawHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");request.setRawHeader("Accept-Language", "zh-cn,zh;q=0.5");request.setRawHeader("Accept-Encoding", "deflate");request.setRawHeader("Accept-Charset", "utf-8;q=0.7,*;q=0.7");request.setRawHeader("Connection", "keep-alive");QNetworkReply* reply = m_manger->get(request);QEventLoop eventLoop;connect(reply,&QNetworkReply::finished,&eventLoop,&QEventLoop::quit);eventLoop.exec(QEventLoop::ExcludeUserInputEvents);strOut = QString::fromUtf8(reply->readAll());reply->close();reply->deleteLater();reply = nullptr;if(!strOut.isEmpty()){strList = strOut.split("<div>");QString key = QString::fromWCharArray(L"厂商名称: ");for(int i=0;i<strList.count();i++){QString str = strList.at(i);int pos = str.indexOf(key);if(pos<0){continue;}str = str.split(key).last();manufacturer = str.split("</div>").first();break;}}}
附: 若要了解如何获取局域网的mac地址,请参考我的csdn的另一篇博文。