liudianwu |
2020-10-18 09:07 |
listAddress.at(2)换成listAddress.at(0)或者1试试,你这直接就显示后面的干嘛?你可以过滤啊,这种一般是IPV6的地址。
- QStringList OnvifHelper::getLocalIps()
{ QStringList ips; QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces(); foreach (const QNetworkInterface &netInterface, netInterfaces) { //移除虚拟机和抓包工具的虚拟网卡 QString humanReadableName = netInterface.humanReadableName().toLower(); if (humanReadableName.startsWith("vmware network adapter") || humanReadableName.startsWith("npcap loopback adapter")) { continue; }
//过滤当前网络接口 bool flag = (netInterface.flags() == (QNetworkInterface::IsUp | QNetworkInterface::IsRunning | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast)); if (flag) { QList<QNetworkAddressEntry> addrs = netInterface.addressEntries(); foreach (QNetworkAddressEntry addr, addrs) { //只取出IPV4的地址 if (addr.ip().protocol() == QAbstractSocket::IPv4Protocol) { QString ip4 = addr.ip().toString(); if (ip4 != "127.0.0.1") { ips.append(ip4); } } } } }
return ips; }
|
|