ZIP Code,Land usw. aus IP Adresse ermitteln

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
bcit6k
User
Beiträge: 77
Registriert: Mittwoch 23. Juli 2008, 08:50

Hallo,

ich bau grad eine abfrage die eine ip adresse in locationdaten wie z.b.: city lan,lon,zip code usw auflöst.
dazu hab ich bis jetzt maxmind verwendet. leider ist die implementierung in python so schwer das ich das nicht geschaft habe.

hat jemand mit so etwas erfahrung? bzw. eine idee wie ich das besser bzw. anders machen kann?

danke
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

bcit6k hat geschrieben:leider ist die implementierung in python so schwer das ich das nicht geschaft habe.
Inwiefern?
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
bcit6k
User
Beiträge: 77
Registriert: Mittwoch 23. Juli 2008, 08:50

von maxmind wird eine dll angeboten, die eine com schnittstelle bereit stellt.
das habich ja noch hin bekommen. auch das beispiel von maxmind in python (das es eigentlich nicht wirklich gibt) wird zwar abgearbeitet, aber er kann das file z.B. nicht laden das ich angebe. ich habe sämmtliche dateipfade durchprobiert usw. nix. beim laden mit der funktion bekomme ich immer ein false zurück. ich habe jetzt den code nicht zur hand werde ihn aber morgen sofort posten.


im prinzip wird ein bin file geladen und da eine ipzeile gelesen.
bcit6k
User
Beiträge: 77
Registriert: Mittwoch 23. Juli 2008, 08:50

Hallo,

so nun hab ich den code zur verfügung

Code: Alles auswählen

import win32com.client
geoip = win32com.client.Dispatch("GeoIPCOMEx.GeoIPEx")
print geoip
print geoip.set_db_path("C:\GeoIP\ ")

print geoip.get_country_code_by_name("www.yahoo.com")
wie man unschwer erkennen kann öffne ich die com schnitstelle
danach verwendet man (laut doku) den befehl set_db_path zum setzen des pfades zu den dat files.
da bekomme ich bereits ein false zurück

die nächste zeile sucht nach der domain im file, da bekomme ich dan logischerweise auch ein false zurück


hier die readme von maxmind

General
-------

GeoIPEx is a COM object wrapper around the Maxmind GeoIP library.
It returns data from the City, ISP and Organization databases.
The only added functionality is recognition of non-routed
IP addresses, for which "dummy" data are returned
(and no DB lookup is done). See "Special addresses" below.


GeoIpEx routines
----------------

CGeoIPEx::set_db_path(BSTR newVal, VARIANT_BOOL *present)
Method; must be called before any other method or property is used
Sets all the suports_* properties.
Note that the booleans returned by methods
must be either VARIANT_TRUE or VARIANT_FALSE.
newVal should be a DIRECTORY not the full path to the
database. The COM object will look for the files
using the directory plus the standard name for the
database as given at the end of this document.

CGeoIPEx::find_by_name(BSTR ip_address, VARIANT_BOOL *found)
Method to find info by DNS name; calls find_ip()
Sets property fields

CGeoIPEx::find_by_addr(BSTR ip_address, VARIANT_BOOL *found)
Method to find info by ip address (dotted quad string); calls find_ip()

CGeoIPEx::get_country_code(BSTR *pVal)
CGeoIPEx::get_country_code3(BSTR *pVal)
CGeoIPEx::get_country_name(BSTR *pVal)
CGeoIPEx::get_region(BSTR *pVal)
CGeoIPEx::get_city(BSTR *pVal)
CGeoIPEx::get_postal_code(BSTR *pVal)
CGeoIPEx::get_latitude(double *pVal)
CGeoIPEx::get_longitude(double *pVal)
CGeoIPEx::get_dma_code(long *pVal)
CGeoIPEx::get_area_code(long *pVal)
CGeoIPEx::get_ISP(BSTR *pVal)
CGeoIPEx::get_organization(BSTR *pVal)
CGeoIPEx::get_error_msg(BSTR *pVal)
Data property reader methods; All return the value from the field with the same name.

CGeoIPEx::get_supports_country_code(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_country_name(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_city(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_country_code3(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_area_code(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_region(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_dma_code(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_postal_code(VARIANT_BOOL *pVal)
CGeoIPEx::get_supports_position(VARIANT_BOOL *pVal)
Property reader methods; All return true if city DB was loaded.

CGeoIPEx::get_supports_ISP(VARIANT_BOOL *pVal)
Property getter method; Return true if ISP DB was loaded.

CGeoIPEx::get_supports_organization(VARIANT_BOOL *pVal)
Property getter method; Return true if org DB was loaded.

Object interface
----------------

Methods:
bool set_db_path(string path) (must be set before any other operations, true if all dbs found)
bool find_by_addr(string ipvalue) (return true if address found, sets all properties)
bool find_by_name(string dns_name) (-"-)

Properties: (string type unless otherwise noted)
country_code (2 chars; "LN" if non-routed addr, "LH" if localhost)
country_code3 (3 chars)
country_name ("Local Area Network" if non-routed addr,"Localhost" if localhost)
region (2 chars, state abbrev for US/Canada, FIPS 10-4 region code for others)
city
postal_code (max 6 chars, US and Canada only)
latitude (real number)
longitude (real number)
dma_code (integer)
area_code (integer)

ISP
organization

supports_country_code (bool, true if db file exists)
supports_country_code3 (bool, true if db file exists)
supports_country_name (bool, true if db file exists)
supports_city (bool, true if db file exists)
supports_region (bool, true if db file exists)
supports_postal_code (bool, true if db file exists)
supports_position (bool, true if db file exists)
supports_area_code (bool, true if db file exists)
supports_dma_code (bool, true if db file exists)

supports_organization (bool, true if db file exists)

supports_isp (bool, true if db file exists)

error_msg (for debugging, set on unexpected failures)



Special addresses
-----------------

If one of the non-routed ip addresses
10.*.*.*
172.16.*.* ... 172.31.*.*
192.168.*.*
are given as input to find_by_addr(),
country_code is set to "LN"
country_name to "Local Area Network" and
all other fields are cleared.

If ip addresses of the form 127.*.*.* (localhost)
are given as input to find_by_addr(),
country_code is set to "LH",
country_name to "Localhost" and
all other fields are cleared.


Database Paths
--------------

Install the databases in the directory set by set_db_path

The names of the files should be the ones listed below.

/path/GeoIP.dat (country)
/path/GeoIPRegion.dat (region)
/path/GeoIPCity.dat (City)
/path/GeoIPISP.dat (ISP)
/path/GeoIPOrg.dat (Organization)

OM Object Registration
----------------------

Copy GeoIpComEx.dll to the "system32" folder

Then open up a DOS command line and run
C:\> cd pathto\system32
C:\WINNT\system32> regsvr32 GeoIpComEx.dll

This should register the COM object so that
you can call it from ASP and other scripts.



ansich nix schlechtes wenns funktionieren würde :)
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Erstens solltest du in Zeile 4 besser entweder doppelte Backslashes verwenden oder Raw-Strings, sonst kann es sein, dass du irgendwann dort aus verstehen Steuerzeichen eingibst und dich dann wunderst warum der Pfad nicht stimmt.

Bist sicher das in dem Ordner alle 5 Dateien drin sind? Hast du das Objekt registriert? Es könnte auch noch helfen wenn du eine Hilfsdatei erstellst, der mit pywin32 mitgelieferte Editor hat irgendwo einen Menüpunkt wo man makepy anweisen kann eine Datei zu erstellen, die statisches Dispatch ermöglicht.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Antworten