AusweisApp2/src/network/WifiInfo.cpp

41 lines
888 B
C++
Raw Normal View History

2017-12-20 14:54:05 +01:00
/*!
2019-05-22 10:08:38 +02:00
* \copyright Copyright (c) 2017-2019 Governikus GmbH & Co. KG, Germany
2017-12-20 14:54:05 +01:00
*/
#include "WifiInfo.h"
2018-03-28 15:10:51 +02:00
#include <QNetworkInterface>
2017-12-20 14:54:05 +01:00
using namespace governikus;
2018-03-28 15:10:51 +02:00
bool WifiInfo::isPrivateIp(const QHostAddress& pAddress)
2017-12-20 14:54:05 +01:00
{
2018-03-28 15:10:51 +02:00
return !pAddress.isNull() &&
(
pAddress.isInSubnet(QHostAddress::parseSubnet(QStringLiteral("10.0.0.0/8"))) ||
pAddress.isInSubnet(QHostAddress::parseSubnet(QStringLiteral("172.16.0.0/12"))) ||
pAddress.isInSubnet(QHostAddress::parseSubnet(QStringLiteral("192.168.0.0/16")))
);
2017-12-20 14:54:05 +01:00
}
2019-01-03 15:06:22 +01:00
bool WifiInfo::hasPrivateIpAddress()
2017-12-20 14:54:05 +01:00
{
2018-03-28 15:10:51 +02:00
const auto& interfaces = QNetworkInterface::allInterfaces();
for (const QNetworkInterface& interface : interfaces)
2017-12-20 14:54:05 +01:00
{
2018-03-28 15:10:51 +02:00
const auto& entries = interface.addressEntries();
for (const QNetworkAddressEntry& addressEntry : entries)
2017-12-20 14:54:05 +01:00
{
2018-03-28 15:10:51 +02:00
if (isPrivateIp(addressEntry.ip()))
{
return true;
}
2017-12-20 14:54:05 +01:00
}
}
2018-03-28 15:10:51 +02:00
return false;
2017-12-20 14:54:05 +01:00
}