QString myClient::getMyIpString()
{
QString ip_address;
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // 获取所有ip
for (int i = 0; i < ipAddressesList.size(); ++i)
{
QHostAddress ipAddr = ipAddressesList.at(i);
if ((ipAddr.protocol() == QAbstractSocket::IPv4Protocol))// 筛选出ipv4
{
qDebug() << "----ipv4: " << ipAddr.toString();
if (!ipAddr.toString().startsWith("169"))// 过滤掉网卡,路由器等的ip
{
ip_address = ipAddr.toString();
break;
}
}
}
if (ip_address.isEmpty())
ip_address = QHostAddress(QHostAddress::LocalHost).toString();
return ip_address;
}
10-24
2167
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-07
4056
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-30
2264
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-15
3361
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)