Skip to content

Commit 7d0b1cd

Browse files
author
borisz
committed
Add support for Netspeed and Confidence and Accuracy Database
1 parent 9134abc commit 7d0b1cd

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Add support for Confidence and Accuracy Database.
2+
* Add support for Netspeed Database. via:
3+
id_by_addr
4+
id_by_name
15
* Add IPv6 glue *** needs libGeoIP 1.4.7 ***
26
country_code_by_name_v6
37
country_name_by_name_v6

README

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Requirements:
22
Python 2.0 or greater
3-
GeoIP C Library 1.4.5 or greater
3+
GeoIP C Library 1.4.7 or greater
44

55
To Install:
66
python setup.py build
@@ -11,6 +11,9 @@ Usage:
1111
See test_org.py for example usage with GeoIP ISP and Organization
1212
See test_city.py for example usage with GeoIP City
1313
See test_region.py for example usage with GeoIP Region
14+
See test_netspeed.py for example usage with GeoIP Netspeed
15+
See test_v6.py for example usage with GeoIP v6 Country Database
16+
See test_city_acc.py for example usage with GeoIP Confidence and Accuracy Database
1417

1518
Troubleshooting:
1619

@@ -20,7 +23,7 @@ directory" error, add /usr/local/lib to /etc/ld.so.conf then run
2023

2124
License:
2225

23-
Copyright (c) 2008 MaxMind LLC
26+
Copyright (c) 2010 MaxMind LLC
2427

2528
All rights reserved. This package is free software; it is licensed
2629
under the LGPL.

py_GeoIP.c

+75-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static PyObject * GeoIP_country_code_by_name_v6_Py(PyObject *self, PyObject *arg
9191
return NULL;
9292
}
9393
retval = GeoIP_country_code_by_name_v6(GeoIP->gi, name);
94-
return Py_BuildValue("s", retval);
94+
return Py_BuildValue("s", retval );
9595
}
9696

9797
static PyObject * GeoIP_country_name_by_name_v6_Py(PyObject *self, PyObject *args) {
@@ -119,12 +119,14 @@ static PyObject * GeoIP_country_code_by_addr_v6_Py(PyObject *self, PyObject *arg
119119
static PyObject * GeoIP_country_name_by_addr_v6_Py(PyObject *self, PyObject *args) {
120120
char * name;
121121
const char * retval;
122+
PyObject * ret;
122123
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
123124
if (!PyArg_ParseTuple(args, "s", &name)) {
124125
return NULL;
125126
}
126127
retval = GeoIP_country_name_by_addr_v6(GeoIP->gi, name);
127-
return Py_BuildValue("s", retval);
128+
ret = Py_BuildValue("s", retval);
129+
return ret;
128130
}
129131

130132
static PyObject * GeoIP_country_code_by_name_Py(PyObject *self, PyObject *args) {
@@ -199,6 +201,28 @@ static PyObject * GeoIP_org_by_name_Py(PyObject *self, PyObject *args) {
199201
return ret;
200202
}
201203

204+
static PyObject * GeoIP_id_by_addr_Py(PyObject *self, PyObject *args) {
205+
char * name;
206+
int i;
207+
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
208+
if (!PyArg_ParseTuple(args, "s", &name)) {
209+
return NULL;
210+
}
211+
i = GeoIP_id_by_addr(GeoIP->gi, name);
212+
return Py_BuildValue("i", i);
213+
}
214+
215+
static PyObject * GeoIP_id_by_name_Py(PyObject *self, PyObject *args) {
216+
char * name;
217+
int i;
218+
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
219+
if (!PyArg_ParseTuple(args, "s", &name)) {
220+
return NULL;
221+
}
222+
i = GeoIP_id_by_name(GeoIP->gi, name);
223+
return Py_BuildValue("i", i);
224+
}
225+
202226
void GeoIP_SetItemString(PyObject *dict, const char * name, const char * value) {
203227
PyObject * nameObj;
204228
PyObject * valueObj;
@@ -229,6 +253,30 @@ void GeoIP_SetItemInt(PyObject *dict, const char * name, int value) {
229253
Py_DECREF(valueObj);
230254
}
231255

256+
void GeoIP_SetConfItemInt(PyObject *dict, const char * name, int value) {
257+
PyObject * nameObj;
258+
PyObject * valueObj;
259+
nameObj = Py_BuildValue("s",name);
260+
valueObj = value == GEOIP_UNKNOWN_CONF
261+
? Py_BuildValue("")
262+
: Py_BuildValue("i",value);
263+
PyDict_SetItem(dict,nameObj,valueObj);
264+
Py_DECREF(nameObj);
265+
Py_DECREF(valueObj);
266+
}
267+
268+
void GeoIP_SetAccuracyItemInt(PyObject *dict, const char * name, int value) {
269+
PyObject * nameObj;
270+
PyObject * valueObj;
271+
nameObj = Py_BuildValue("s",name);
272+
valueObj = value == GEOIP_UNKNOWN_ACCURACY_RADIUS
273+
? Py_BuildValue("")
274+
: Py_BuildValue("i",value);
275+
PyDict_SetItem(dict,nameObj,valueObj);
276+
Py_DECREF(nameObj);
277+
Py_DECREF(valueObj);
278+
}
279+
232280
static PyObject * GeoIP_region_populate_dict(GeoIPRegion * gir) {
233281
PyObject * retval;
234282
const char * region_name = NULL;
@@ -268,6 +316,14 @@ static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) {
268316
GeoIP_region_name_by_code(gir->country_code, gir->region));
269317
GeoIP_SetItemString(retval, "time_zone",
270318
GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region));
319+
320+
GeoIP_SetConfItemInt(retval, "country_conf", gir->country_conf );
321+
GeoIP_SetConfItemInt(retval, "region_conf", gir->region_conf );
322+
GeoIP_SetConfItemInt(retval, "city_conf", gir->city_conf );
323+
GeoIP_SetConfItemInt(retval, "postal_conf", gir->postal_conf );
324+
325+
GeoIP_SetAccuracyItemInt(retval, "accuracy_radius", gir->accuracy_radius );
326+
271327
GeoIPRecord_delete(gir);
272328
return retval;
273329
}
@@ -391,6 +447,8 @@ static PyMethodDef GeoIP_Object_methods[] = {
391447
{"country_name_by_name_v6", GeoIP_country_name_by_name_v6_Py, 1, "Lookup IPv6 Country Name By Name"},
392448
{"country_code_by_addr_v6", GeoIP_country_code_by_addr_v6_Py, 1, "Lookup IPv6 Country Code By IP Address"},
393449
{"country_name_by_addr_v6", GeoIP_country_name_by_addr_v6_Py, 1, "Lookup IPv6 Country Name By IP Address"},
450+
{"id_by_addr", GeoIP_id_by_addr_Py, 1, "Lookup Netspeed By IP Address"},
451+
{"id_by_name", GeoIP_id_by_name_Py, 1, "Lookup Netspeed By Name"},
394452
{NULL, NULL, 0, NULL}
395453
};
396454

@@ -501,4 +559,19 @@ initGeoIP(void)
501559
PyDict_SetItemString(d, "GEOIP_CHARSET_UTF8", tmp);
502560
Py_DECREF(tmp);
503561

562+
tmp = PyInt_FromLong(GEOIP_UNKNOWN_SPEED);
563+
PyDict_SetItemString(d, "GEOIP_UNKNOWN_SPEED", tmp);
564+
Py_DECREF(tmp);
565+
566+
tmp = PyInt_FromLong(GEOIP_DIALUP_SPEED);
567+
PyDict_SetItemString(d, "GEOIP_DIALUP_SPEED", tmp);
568+
Py_DECREF(tmp);
569+
570+
tmp = PyInt_FromLong(GEOIP_CABLEDSL_SPEED);
571+
PyDict_SetItemString(d, "GEOIP_CABLEDSL_SPEED", tmp);
572+
Py_DECREF(tmp);
573+
574+
tmp = PyInt_FromLong(GEOIP_CORPORATE_SPEED);
575+
PyDict_SetItemString(d, "GEOIP_CORPORATE_SPEED", tmp);
576+
Py_DECREF(tmp);
504577
}

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
include_dirs = ['/usr/local/include'])
88

99
setup (name = 'GeoIP-Python',
10-
version = '1.2.4',
10+
version = '1.2.5',
1111
description = 'This is a python wrapper to GeoIP',
1212
ext_modules = [module1])

0 commit comments

Comments
 (0)