28 #include "ip2c/ip2ccountry.h"
29 #include "ip2c/ip2crange.h"
32 #include <QHostAddress>
48 class IP2C :
public QObject
66 static IP2C *instance();
67 static void deinstantiate();
75 const QPixmap flagLan;
76 const QPixmap flagLocalhost;
77 const QPixmap flagUnknown;
79 const QPixmap &flag(
const QString &countryCode);
82 bool isDataAccessLocked()
const
84 return bDataAccessLocked;
87 int numKnownEntries()
const
89 return database.size();
101 IP2CCountry countryInfoForAddress(
const QHostAddress &ipaddress)
107 void setDataAccessLockEnabled(
bool b)
109 bDataAccessLocked = b;
120 this->database = sortedRanges;
124 static QMutex instanceMutex;
125 static IP2C *staticInstance;
134 bool bDataAccessLocked;
135 QList<IP2CRange> database;
136 QHash<QString, IP2CCountry> countries;
141 const QHash<QString, QPixmap> flags;
145 QSet<QString> unknownCountries;
146 QSet<QString> unknownFlags;
150 Q_DISABLE_COPY(
IP2C);
155 const IP2CRange &lookupIP(
unsigned int ipaddress);
158 void logUnknownCountry(
const QString &countryCode);
159 void logUnknownFlag(
const QString &countryCode);
161 inline bool isLANAddress(
unsigned ipv4Address)
163 const static unsigned LAN_1_BEGIN = QHostAddress(
"10.0.0.0").toIPv4Address();
164 const static unsigned LAN_1_END = QHostAddress(
"10.255.255.255").toIPv4Address();
165 const static unsigned LAN_2_BEGIN = QHostAddress(
"172.16.0.0").toIPv4Address();
166 const static unsigned LAN_2_END = QHostAddress(
"172.31.255.255").toIPv4Address();
167 const static unsigned LAN_3_BEGIN = QHostAddress(
"192.168.0.0").toIPv4Address();
168 const static unsigned LAN_3_END = QHostAddress(
"192.168.255.255").toIPv4Address();
171 (ipv4Address >= LAN_1_BEGIN && ipv4Address <= LAN_1_END)
172 || (ipv4Address >= LAN_2_BEGIN && ipv4Address <= LAN_2_END)
173 || (ipv4Address >= LAN_3_BEGIN && ipv4Address <= LAN_3_END)
177 inline bool isLocalhostAddress(
unsigned ipv4Address)
179 const static unsigned LOCALHOST_BEGIN = QHostAddress(
"127.0.0.0").toIPv4Address();
180 const static unsigned LOCALHOST_END = QHostAddress(
"127.255.255.255").toIPv4Address();
182 return ipv4Address >= LOCALHOST_BEGIN && ipv4Address <= LOCALHOST_END;