diff --git a/ChangeLog b/ChangeLog index 5c7e13b..779000e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1.2.7 2011-08-23 + * Add example test_netspeedcell.py ( Boris Zentner ) +1.2.6 2011-06-06 + * Add new methods record_by_name_v6 and record_by_addr_v6 to support + GeoIPCityv6 databases. ( Boris Zentner ) 1.2.5 2011-05-10 * Remove Confidence and Accuracy Database it is unsued anyway. ( Boris Zentner ) diff --git a/README b/README index 535d51a..8d4aaa2 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ Requirements: Python 2.0 or greater - GeoIP C Library 1.4.7 or greater + GeoIP C Library 1.4.8 or greater To Install: python setup.py build diff --git a/py_GeoIP.c b/py_GeoIP.c index 7f3a9a5..a12cda0 100644 --- a/py_GeoIP.c +++ b/py_GeoIP.c @@ -337,6 +337,36 @@ static PyObject * GeoIP_populate_dict(GeoIP* gi, GeoIPRecord *gir) { return retval; } +static PyObject * GeoIP_record_by_addr_v6_Py(PyObject *self, PyObject *args) { + char * addr; + GeoIPRecord * gir; + GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self; + if (!PyArg_ParseTuple(args, "s", &addr)) { + return NULL; + } + gir = GeoIP_record_by_addr_v6(GeoIP->gi, addr); + if (gir == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + return GeoIP_populate_dict(GeoIP->gi, gir); +} + +static PyObject * GeoIP_record_by_name_v6_Py(PyObject *self, PyObject *args) { + char * name; + GeoIPRecord * gir; + GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self; + if (!PyArg_ParseTuple(args, "s", &name)) { + return NULL; + } + gir = GeoIP_record_by_name_v6(GeoIP->gi, name); + if (gir == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + return GeoIP_populate_dict(GeoIP->gi, gir); +} + static PyObject * GeoIP_record_by_addr_Py(PyObject *self, PyObject *args) { char * addr; GeoIPRecord * gir; @@ -465,8 +495,6 @@ static PyObject * GeoIP_time_zone_by_country_and_region_Py(PyObject *self, PyObj return Py_BuildValue("s", GeoIP_time_zone_by_country_and_region(country_code, region)); } - - static PyMethodDef GeoIP_Object_methods[] = { {"country_code_by_name", GeoIP_country_code_by_name_Py, 1, "Lookup Country Code By Name"}, {"country_name_by_name", GeoIP_country_name_by_name_Py, 1, "Lookup Country Name By Name"}, @@ -490,6 +518,8 @@ static PyMethodDef GeoIP_Object_methods[] = { {"teredo", GeoIP_teredo_Py, 1, "Returns true if teredo is enabled"}, {"id_by_addr", GeoIP_id_by_addr_Py, 1, "Lookup Netspeed By IP Address"}, {"id_by_name", GeoIP_id_by_name_Py, 1, "Lookup Netspeed By Name"}, + {"record_by_addr_v6", GeoIP_record_by_addr_v6_Py, 1, "Lookup City Region By IP Address"}, + {"record_by_name_v6", GeoIP_record_by_name_v6_Py, 1, "Lookup City Region By Name"}, {NULL, NULL, 0, NULL} }; diff --git a/setup.py b/setup.py index 4a8c9a3..c34324a 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,6 @@ include_dirs = ['/usr/local/include']) setup (name = 'GeoIP-Python', - version = '1.2.5', + version = '1.2.7', description = 'This is a python wrapper to GeoIP', ext_modules = [module1]) diff --git a/test.py b/test.py index 774e97a..9e976a7 100755 --- a/test.py +++ b/test.py @@ -12,4 +12,5 @@ print gi.country_code_by_addr("24.24.24.24") print gi.country_name_by_addr("24.24.24.24") print gi.range_by_ip("68.180.206.184") +print GeoIP.lib_version() diff --git a/test_city_acc.py b/test_city_acc.py new file mode 100755 index 0000000..388ad3e --- /dev/null +++ b/test_city_acc.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +import GeoIP + +gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCityConfidenceDist.dat",GeoIP.GEOIP_STANDARD) + +gir = gi.record_by_name("www.google.com") +#gir = gi.record_by_addr("24.24.24.24") + +if gir != None: + print gir['country_code'] + print gir['country_code3'] + print gir['country_name'] + print gir['city'] + print gir['region'] + print gir['region_name'] + print gir['postal_code'] + print gir['latitude'] + print gir['longitude'] + print gir['area_code'] + print gir['time_zone'] + print gir['metro_code'] + print gir['country_conf'] + print gir['region_conf'] + print gir['city_conf'] + print gir['postal_conf'] + print gir['accuracy_radius'] + diff --git a/test_city_charset.py.old b/test_city_charset.py.old new file mode 100755 index 0000000..86d6bfe --- /dev/null +++ b/test_city_charset.py.old @@ -0,0 +1,35 @@ +#!/usr/bin/python + +import GeoIP + +# open the citydatabase. All cities return in iso-8859-1 by default +gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCity.dat",GeoIP.GEOIP_STANDARD) + +# lookup a record, where cityname contains chars > 127 ( eg != ascii ) +gir = gi.record_by_name("www.osnabrueck.de") + +# print the cityname with iso-8859-1 charset +print gir['city']; + +# print the cityname transformed to utf8 +print unicode(gir['city'], 'iso-8859-1') + +# however, at your option GeoIP can return the cityname in utf8 +# just put GeoIP into utf8 mode +# +# from now on all records returns in UTF8 until you change the charset again +# Notice, that all previous records return in the previous charset +gi.set_charset(GeoIP.GEOIP_CHARSET_UTF8); + +# get a new record, now in utf8 +gir2 = gi.record_by_name("www.osnabrueck.de") + +# and print it ( should be the same output as on line 2 ) +print gir2['city'] + +## Some more charset examples +# current_charset = gi.charset() +# old_charset = gi.set_charset(GeoIP.GEOIP_CHARSET_ISO_8859_1); + + + diff --git a/test_netspeedcell.py b/test_netspeedcell.py new file mode 100755 index 0000000..102d589 --- /dev/null +++ b/test_netspeedcell.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +import GeoIP + +gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPNetSpeedCell.dat",GeoIP.GEOIP_STANDARD) + +print gi.org_by_name("yahoo.com") +print gi.org_by_name("www.google.com") +print gi.org_by_addr("24.24.24.24") diff --git a/time_zone.py b/time_zone.py new file mode 100755 index 0000000..c2745ca --- /dev/null +++ b/time_zone.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +import GeoIP + +#1.4.7 +#Europe/Berlin +#Europe/Berlin +#None +#America/Los_Angeles +#America/New_York + +print GeoIP.lib_version() +print GeoIP.time_zone_by_country_and_region("DE", 'XY') +print GeoIP.time_zone_by_country_and_region("DE", '') +print GeoIP.time_zone_by_country_and_region("US", "") +print GeoIP.time_zone_by_country_and_region("US", "CA") +print GeoIP.time_zone_by_country_and_region("US", "MA") +