21#include <QHostAddress>
26 : QObject(parent), _db(0)
41 _db = GeoIP_open(fname.toLocal8Bit().constData(), GEOIP_STANDARD);
43 GeoIP_set_charset(
_db, GEOIP_CHARSET_UTF8);
46 vError(
"Unable to open local GeoIP database: %1").arg(fname);
71 switch (
_db->databaseType) {
72 case GEOIP_COUNTRY_EDITION:
73 case GEOIP_COUNTRY_EDITION_V6:
76 case GEOIP_CITY_EDITION_REV0:
77 case GEOIP_CITY_EDITION_REV1:
80 case GEOIP_REGION_EDITION_REV0:
81 case GEOIP_REGION_EDITION_REV1:
84 case GEOIP_ORG_EDITION:
87 case GEOIP_ISP_EDITION:
90 case GEOIP_PROXY_EDITION:
93 case GEOIP_ASNUM_EDITION:
96 case GEOIP_NETSPEED_EDITION:
99 case GEOIP_DOMAIN_EDITION:
110 if (
isOpen() && ! ip.isNull()) {
111 const char *addr = ip.toString().toAscii().constData();
112 const char *countryCode = GeoIP_country_code_by_addr(
_db, addr);
114 return QString::fromUtf8(countryCode);
122 if (
isOpen() && ! ip.isNull()) {
123 const char *addr = ip.
toString().toAscii().constData();
126 if (ip.protocol() == QAbstractSocket::IPv6Protocol)
127 r = GeoIP_record_by_addr_v6(
_db, addr);
129 r = GeoIP_record_by_addr(
_db, addr);
132 QString countryCode = QString::fromUtf8(r->country_code);
133 QString countryName = QString::fromUtf8(r->country_name);
134 QString city = QString::fromUtf8(r->city);
137 const char *regionName = GeoIP_region_name_by_code(r->country_code,
140 region = QString::fromUtf8(regionName);
142 return GeoIpRecord(ip, r->latitude, r->longitude, city, region,
143 countryName, countryCode);
GeoIpRecord recordByAddr(const QHostAddress &ip)
GeoIpDatabase(QObject *parent=0)
GeoIpDatabase::DatabaseType type() const
bool open(const QString &fname)
QString countryCodeByAddr(const QHostAddress &ip)