Re: [WebDNA] Re: anyone get MaxMind geolite city working?

This WebDNA talk-list message is from

2012


It keeps the original formatting.
numero = 108677
interpreted = N
texte = This is a multi-part message in MIME format. --------------080801090200070503000103 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit If you want to run geocoding locally, here is a quick version that works 1. Install these dbs posted here: (about 120 megs uncompressed) http://www.kanuhawaii.org/downloads/geolocation.zip 2. Load up a function like this: [function name=geocode] GeoLiteCity-Location.db locId country region city postalCode latitude longitude metroCode areaCode GeoLiteCity-Blocks startIpNum,endIpNum,locId [text]temp=[middle startAfter=.&endBefore=.][ip][/middle][/text] [math]four=[middle startAfter=.][middle startAfter=.][middle startAfter=.][ip][/middle][/middle][/middle][/math] [math]one=[middle startAfter=&endBefore=[temp]][ip][/middle][/math] [math]two=[middle startAfter=&endBefore=.][temp][/middle][/math] [math]three=[middle startAfter=.][temp][/middle][/math] [math]thisnum=(16777216*[one])+(65536*[two])+(256*[three])+[four][/math] [search db=/db/geolocation/GeoLiteCity-Blocks.db&geendIpNumdatarq=[thisnum]&endIpNumtype=num&max=1&rank=off] [foundItems] [return][lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=city&NotFound=Error, probably mobile device], [lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=region][/return] [/foundItems] [/search] [return][/return] [/function] 3. Call the function via [geocode ip=[the ip address you want to geocode]] In the function, you can return any of the fields from the GeoLiteCity-Location.db via the last lookup call. By default this returns the city and state/province. You could probably rewrite this to run faster but I just need this to batch convert so this is good enough. Because of the size of these tables (my guess) I couldn't get WebDNA to do a search with two columns that are typed num so I had to just search one, rank it off so it would return results without sorting, and take the first result. Olin Lagon wrote: > Yes the tables should be updated regularly. The free version is > updated monthly. But for our purpose 96% or so is good enough for us > and we won't update that often. > > I did find with my testing that some mobile IP address are causing > problems. One, some folks access sites via mobile and the IP is tied > to other locations and two, some mobile IPs are not in the MaxMind tables. > > Anyway, I got a couple of requests and will post my code and link to > converted tables later today. The raw tables are large 100 megs+ so > editing the tables requires editors that can handle large files (I use > VIM). > > Tom Duke wrote: >> Olin, >> >> Hi - I was using a [TCPConnect] api call to these guys for one client: >> >> http://ipinfodb.com/ip_location_api.php >> >> it went down for a while though and caused problems so I disabled it. >> I thought of trying to locally host the databases - but do they not >> need to be updated regularly? >> >> - Tom >> >> >> --------------------------------------------------------- This >> message is sent to you because you are subscribed to the mailing list >> . To unsubscribe, E-mail to: archives: >> http://mail.webdna.us/list/talk@webdna.us Bug Reporting: >> support@webdna.us --------------080801090200070503000103 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit If you want to run geocoding locally, here is a quick version that works

1. Install these dbs posted here: (about 120 megs uncompressed) http://www.kanuhawaii.org/downloads/geolocation.zip

2. Load up a function like this:

[function name=geocode]

    GeoLiteCity-Location.db
    locId    country    region    city    postalCode    latitude    longitude    metroCode    areaCode
   
    GeoLiteCity-Blocks
    startIpNum,endIpNum,locId
       
    [text]temp=[middle startAfter=.&endBefore=.][ip][/middle][/text]
    [math]four=[middle startAfter=.][middle startAfter=.][middle startAfter=.][ip][/middle][/middle][/middle][/math]
    [math]one=[middle startAfter=&endBefore=[temp]][ip][/middle][/math]
    [math]two=[middle startAfter=&endBefore=.][temp][/middle][/math]
    [math]three=[middle startAfter=.][temp][/middle][/math]
    [math]thisnum=(16777216*[one])+(65536*[two])+(256*[three])+[four][/math]

    [search db=/db/geolocation/GeoLiteCity-Blocks.db&geendIpNumdatarq=[thisnum]&endIpNumtype=num&max=1&rank=off]
    [foundItems]
          [return][lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=city&NotFound=Error, probably mobile device], [lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=region][/return]
        [/foundItems]
    [/search]

    [return][/return]
[/function]

3. Call the function via [geocode ip=[the ip address you want to geocode]]

In the function, you can return any of the fields from the GeoLiteCity-Location.db via the last lookup call. By default this returns the city and state/province.

You could probably rewrite this to run faster but I just need this to batch convert so this is good enough. Because of the size of these tables (my guess) I couldn't get WebDNA to do a search with two columns that are typed num so I had to just search one, rank it off so it would return results without sorting, and take the first result.

Olin Lagon wrote:
Yes the tables should be updated regularly. The free version is updated monthly. But for our purpose 96% or so is good enough for us and we won't update that often.

I did find with my testing that some mobile IP address are causing problems. One, some folks access sites via mobile and the IP is tied to other locations and two, some mobile IPs are not in the MaxMind tables.

Anyway, I got a couple of requests and will post my code and link to converted tables later today. The raw tables are large 100 megs+ so editing the tables requires editors that can handle large files (I use VIM).

Tom Duke wrote:
Olin,

Hi - I was using a [TCPConnect] api call to these guys for one client:

    http://ipinfodb.com/ip_location_api.php

it went down for a while though and caused problems so I disabled it.   I thought of trying to locally host the databases - but do they not need to be updated regularly?

- Tom


--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us
--------------080801090200070503000103-- Associated Messages, from the most recent to the oldest:

    
  1. [WebDNA] anyone get MaxMind geolite city working? (Olin Lagon 2012)
This is a multi-part message in MIME format. --------------080801090200070503000103 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit If you want to run geocoding locally, here is a quick version that works 1. Install these dbs posted here: (about 120 megs uncompressed) http://www.kanuhawaii.org/downloads/geolocation.zip 2. Load up a function like this: [function name=geocode] GeoLiteCity-Location.db locId country region city postalCode latitude longitude metroCode areaCode GeoLiteCity-Blocks startIpNum,endIpNum,locId [text]temp=[middle startAfter=.&endBefore=.][ip][/middle][/text] [math]four=[middle startAfter=.][middle startAfter=.][middle startAfter=.][ip][/middle][/middle][/middle][/math] [math]one=[middle startAfter=&endBefore=[temp]][ip][/middle][/math] [math]two=[middle startAfter=&endBefore=.][temp][/middle][/math] [math]three=[middle startAfter=.][temp][/middle][/math] [math]thisnum=(16777216*[one])+(65536*[two])+(256*[three])+[four][/math] [search db=/db/geolocation/GeoLiteCity-Blocks.db&geendIpNumdatarq=[thisnum]&endIpNumtype=num&max=1&rank=off] [founditems] [return][lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=city&NotFound=Error, probably mobile device], [lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=region][/return] [/foundItems] [/search] [return][/return] [/function] 3. Call the function via [geocode ip=[the ip address you want to geocode]] In the function, you can return any of the fields from the GeoLiteCity-Location.db via the last lookup call. By default this returns the city and state/province. You could probably rewrite this to run faster but I just need this to batch convert so this is good enough. Because of the size of these tables (my guess) I couldn't get WebDNA to do a search with two columns that are typed num so I had to just search one, rank it off so it would return results without sorting, and take the first result. Olin Lagon wrote: > Yes the tables should be updated regularly. The free version is > updated monthly. But for our purpose 96% or so is good enough for us > and we won't update that often. > > I did find with my testing that some mobile IP address are causing > problems. One, some folks access sites via mobile and the IP is tied > to other locations and two, some mobile IPs are not in the MaxMind tables. > > Anyway, I got a couple of requests and will post my code and link to > converted tables later today. The raw tables are large 100 megs+ so > editing the tables requires editors that can handle large files (I use > VIM). > > Tom Duke wrote: >> Olin, >> >> Hi - I was using a [tcpconnect] api call to these guys for one client: >> >> http://ipinfodb.com/ip_location_api.php >> >> it went down for a while though and caused problems so I disabled it. >> I thought of trying to locally host the databases - but do they not >> need to be updated regularly? >> >> - Tom >> >> >> --------------------------------------------------------- This >> message is sent to you because you are subscribed to the mailing list >> . To unsubscribe, E-mail to: archives: >> http://mail.webdna.us/list/talk@webdna.us Bug Reporting: >> support@webdna.us --------------080801090200070503000103 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit If you want to run geocoding locally, here is a quick version that works

1. Install these dbs posted here: (about 120 megs uncompressed) http://www.kanuhawaii.org/downloads/geolocation.zip

2. Load up a function like this:

[function name=geocode]

    GeoLiteCity-Location.db
    locId    country    region    city    postalCode    latitude    longitude    metroCode    areaCode
   
    GeoLiteCity-Blocks
    startIpNum,endIpNum,locId
       
    [text]temp=[middle startAfter=.&endBefore=.][ip][/middle][/text]
    [math]four=[middle startAfter=.][middle startAfter=.][middle startAfter=.][ip][/middle][/middle][/middle][/math]
    [math]one=[middle startAfter=&endBefore=[temp]][ip][/middle][/math]
    [math]two=[middle startAfter=&endBefore=.][temp][/middle][/math]
    [math]three=[middle startAfter=.][temp][/middle][/math]
    [math]thisnum=(16777216*[one])+(65536*[two])+(256*[three])+[four][/math]

    [search db=/db/geolocation/GeoLiteCity-Blocks.db&geendIpNumdatarq=[thisnum]&endIpNumtype=num&max=1&rank=off]
    [founditems]
          [return][lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=city&NotFound=Error, probably mobile device], [lookup db=/db/geolocation/GeoLiteCity-Location.db&value=[locId]&lookinfield=locId&returnfield=region][/return]
        [/foundItems]
    [/search]

    [return][/return]
[/function]

3. Call the function via [geocode ip=[the ip address you want to geocode]]

In the function, you can return any of the fields from the GeoLiteCity-Location.db via the last lookup call. By default this returns the city and state/province.

You could probably rewrite this to run faster but I just need this to batch convert so this is good enough. Because of the size of these tables (my guess) I couldn't get WebDNA to do a search with two columns that are typed num so I had to just search one, rank it off so it would return results without sorting, and take the first result.

Olin Lagon wrote:
Yes the tables should be updated regularly. The free version is updated monthly. But for our purpose 96% or so is good enough for us and we won't update that often.

I did find with my testing that some mobile IP address are causing problems. One, some folks access sites via mobile and the IP is tied to other locations and two, some mobile IPs are not in the MaxMind tables.

Anyway, I got a couple of requests and will post my code and link to converted tables later today. The raw tables are large 100 megs+ so editing the tables requires editors that can handle large files (I use VIM).

Tom Duke wrote:
Olin,

Hi - I was using a [tcpconnect] api call to these guys for one client:

    http://ipinfodb.com/ip_location_api.php

it went down for a while though and caused problems so I disabled it.   I thought of trying to locally host the databases - but do they not need to be updated regularly?

- Tom


--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us
--------------080801090200070503000103-- Olin Lagon

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

Re1000001: Setting up shop (1997) AuthorizeNet Declines (2005) Creating a back button (1999) Trouble with formula.db (1997) a little OT (2001) Intranet Tempaltes? (2004) Requiring that certain fields be completed (1997) getchars broken? (1997) [WebDNA] Hmmm ... (2008) WebMerchant 1.6 and https (1997) WebCat2b15MacPlugin - showing [math] (1997) WC 4.0 and WebStar 4.1 on Mac OS (2000) emailer don't work (1998) Size images (2002) Web Catalog 2 demo (1997) shownext problems (1998) same bill to and ship to? (1998) Using Applescript to process WebCatalog functions (1998) Duplicates (1998) Re:2nd WebCatalog2 Feature Request (1996)