IPAddressCountry & Iso3166CountryLongitudeLatitude

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

IPAddressCountry & Iso3166CountryLongitudeLatitude

Sven Van Caekenberghe
I want to share a couple of classes.

Did you ever want to add this trick to your website where you do something based on the country your visitors are from ? Now you can do so in Smalltalk !

T3EasyUtils getIpAddressCountry atAddress: '81.83.7.35'

        #BE

T3EasyUtils getIso3166CountryLongitudeLatitude at: #BE

        4.0@50.8333
       
#('www.beta9.be' 'www.inria.fr' 'nic.st' 'www.world.st' 'www.pharo-project.org')
        collect: [ :each | T3EasyUtils getIpAddressCountry atAddress: (NetNameResolver addressForName: each) ]

        #(#BE #FR #SE #US #CH)

(T3EasyUtils is holding unique, loaded instances of IPAddressCountry & Iso3166CountryLongitudeLatitude).

As this is part of one of our commercial applications, you can even access it over the internet as a JSON REST call:

$ curl http://easy.t3-platform.net/rest/geo-ip?address=81.83.7.35

        {"latitude":50.8333,"address":"81.83.7.35","country":"BE","longitude":4.0}

(Please note that this is not a public service as such, you can try it, but you are not supposed to call this from your own applications.)

BTW, T3 Easy is our new entry level track & trace product, an HTML5 web app (using client side HTML+Javascript+CSS) on top of a REST server written in Pharo Smalltalk. It consists of 4 stateless Pharo Cog VM's running behind an Apache load balancer. The server uses Zinc HTTP Components, both for its server part, as well as for clients talking to other systems behind the scenes. Even the Open Street Map tile serving, which is pushing out many megabytes, is currently going through this server.

Here is a live demo URL in case your are curious:

        http://easy.t3-platform.net?t=livedemo

(You need a fast web browser like Google Chrome, Safari, Opera 10 or Firefox 4.)

The code for IPAddressCountry & Iso3166CountryLongitudeLatitude is on SqueakSource:

        http://www.squeaksource.com/ADayAtTheBeach.html

These are the class comments:

---

IPAddressCountry maps IP addresses to their country code.
I hold a collection of IPAddressRangeCountry objects that I do a binary search on.

I am constructed based on a CSV data file using my class' #readFrom:
which expects lines like 3651886848,3651887103,BE or start,stop,code

You can download a version of this file from http://homepage.mac.com/svc/data/GeoIPCountry.csv.gz

((IPAddressCountry readFrom: 'GeoIPCountry.csv') atAddress: '81.83.7.35') = #BE

Addresses can also be specified as #(81 83 7 35) for #atAddress: or as 1364395811 for #at:

You should cache one instance of me.

Based on data from http://www.maxmind.com/app/geolitecountry

---

Iso3166CountryLongitudeLatitude maps country codes to their average or central longtiude/latitude.

My keys are two letter Iso3166 Symbols representing a country, such as #BE
My values are Points holding coordinates as longtiude@latitude

I am constructed based on a CSV data file using my class' #readFrom:
which expects lines like BE,50.8333,4.0000 or code,latitude,longitude

You can download a version of this file from http://homepage.mac.com/svc/data/CountryLatLong.csv.gz

((Iso3166CountryLongitudeLatitude readFrom: 'CountryLatLong.csv') at: #BE) = 4.0@50.8333

You should cache one instance of me.

---

Sven



Reply | Threaded
Open this post in threaded view
|

Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Henrik Sperre Johansen
But....
I thought the proper way to track IP adresses was to create a GUI interface in Visual Basic!

Joke aside, really neat stuff :D

Cheers,
Henry

PS. I take it you'd be interested in updating SmallInteger digitAt: / digitLength to work in 64bit images if they become available? ;)

On Apr 4, 2011, at 3:21 09PM, Sven Van Caekenberghe wrote:

> I want to share a couple of classes.
>
> Did you ever want to add this trick to your website where you do something based on the country your visitors are from ? Now you can do so in Smalltalk !
>
> T3EasyUtils getIpAddressCountry atAddress: '81.83.7.35'
>
> #BE
>
> T3EasyUtils getIso3166CountryLongitudeLatitude at: #BE
>
> 4.0@50.8333
>
> #('www.beta9.be' 'www.inria.fr' 'nic.st' 'www.world.st' 'www.pharo-project.org')
> collect: [ :each | T3EasyUtils getIpAddressCountry atAddress: (NetNameResolver addressForName: each) ]
>
> #(#BE #FR #SE #US #CH)
>
> (T3EasyUtils is holding unique, loaded instances of IPAddressCountry & Iso3166CountryLongitudeLatitude).
>
> As this is part of one of our commercial applications, you can even access it over the internet as a JSON REST call:
>
> $ curl http://easy.t3-platform.net/rest/geo-ip?address=81.83.7.35
>
> {"latitude":50.8333,"address":"81.83.7.35","country":"BE","longitude":4.0}
>
> (Please note that this is not a public service as such, you can try it, but you are not supposed to call this from your own applications.)
>
> BTW, T3 Easy is our new entry level track & trace product, an HTML5 web app (using client side HTML+Javascript+CSS) on top of a REST server written in Pharo Smalltalk. It consists of 4 stateless Pharo Cog VM's running behind an Apache load balancer. The server uses Zinc HTTP Components, both for its server part, as well as for clients talking to other systems behind the scenes. Even the Open Street Map tile serving, which is pushing out many megabytes, is currently going through this server.
>
> Here is a live demo URL in case your are curious:
>
> http://easy.t3-platform.net?t=livedemo
>
> (You need a fast web browser like Google Chrome, Safari, Opera 10 or Firefox 4.)
>
> The code for IPAddressCountry & Iso3166CountryLongitudeLatitude is on SqueakSource:
>
> http://www.squeaksource.com/ADayAtTheBeach.html
>
> These are the class comments:
>
> ---
>
> IPAddressCountry maps IP addresses to their country code.
> I hold a collection of IPAddressRangeCountry objects that I do a binary search on.
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like 3651886848,3651887103,BE or start,stop,code
>
> You can download a version of this file from http://homepage.mac.com/svc/data/GeoIPCountry.csv.gz
>
> ((IPAddressCountry readFrom: 'GeoIPCountry.csv') atAddress: '81.83.7.35') = #BE
>
> Addresses can also be specified as #(81 83 7 35) for #atAddress: or as 1364395811 for #at:
>
> You should cache one instance of me.
>
> Based on data from http://www.maxmind.com/app/geolitecountry
>
> ---
>
> Iso3166CountryLongitudeLatitude maps country codes to their average or central longtiude/latitude.
>
> My keys are two letter Iso3166 Symbols representing a country, such as #BE
> My values are Points holding coordinates as longtiude@latitude
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like BE,50.8333,4.0000 or code,latitude,longitude
>
> You can download a version of this file from http://homepage.mac.com/svc/data/CountryLatLong.csv.gz
>
> ((Iso3166CountryLongitudeLatitude readFrom: 'CountryLatLong.csv') at: #BE) = 4.0@50.8333
>
> You should cache one instance of me.
>
> ---
>
> Sven
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Miguel Cobá
In reply to this post by Sven Van Caekenberghe
Amazing app, you have there. Looks very professional. And the interface
is very attractive.

Good job!

El lun, 04-04-2011 a las 15:21 +0200, Sven Van Caekenberghe escribió:

> I want to share a couple of classes.
>
> Did you ever want to add this trick to your website where you do something based on the country your visitors are from ? Now you can do so in Smalltalk !
>
> T3EasyUtils getIpAddressCountry atAddress: '81.83.7.35'
>
> #BE
>
> T3EasyUtils getIso3166CountryLongitudeLatitude at: #BE
>
> 4.0@50.8333
>
> #('www.beta9.be' 'www.inria.fr' 'nic.st' 'www.world.st' 'www.pharo-project.org')
> collect: [ :each | T3EasyUtils getIpAddressCountry atAddress: (NetNameResolver addressForName: each) ]
>
> #(#BE #FR #SE #US #CH)
>
> (T3EasyUtils is holding unique, loaded instances of IPAddressCountry & Iso3166CountryLongitudeLatitude).
>
> As this is part of one of our commercial applications, you can even access it over the internet as a JSON REST call:
>
> $ curl http://easy.t3-platform.net/rest/geo-ip?address=81.83.7.35
>
> {"latitude":50.8333,"address":"81.83.7.35","country":"BE","longitude":4.0}
>
> (Please note that this is not a public service as such, you can try it, but you are not supposed to call this from your own applications.)
>
> BTW, T3 Easy is our new entry level track & trace product, an HTML5 web app (using client side HTML+Javascript+CSS) on top of a REST server written in Pharo Smalltalk. It consists of 4 stateless Pharo Cog VM's running behind an Apache load balancer. The server uses Zinc HTTP Components, both for its server part, as well as for clients talking to other systems behind the scenes. Even the Open Street Map tile serving, which is pushing out many megabytes, is currently going through this server.
>
> Here is a live demo URL in case your are curious:
>
> http://easy.t3-platform.net?t=livedemo
>
> (You need a fast web browser like Google Chrome, Safari, Opera 10 or Firefox 4.)
>
> The code for IPAddressCountry & Iso3166CountryLongitudeLatitude is on SqueakSource:
>
> http://www.squeaksource.com/ADayAtTheBeach.html
>
> These are the class comments:
>
> ---
>
> IPAddressCountry maps IP addresses to their country code.
> I hold a collection of IPAddressRangeCountry objects that I do a binary search on.
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like 3651886848,3651887103,BE or start,stop,code
>
> You can download a version of this file from http://homepage.mac.com/svc/data/GeoIPCountry.csv.gz
>
> ((IPAddressCountry readFrom: 'GeoIPCountry.csv') atAddress: '81.83.7.35') = #BE
>
> Addresses can also be specified as #(81 83 7 35) for #atAddress: or as 1364395811 for #at:
>
> You should cache one instance of me.
>
> Based on data from http://www.maxmind.com/app/geolitecountry
>
> ---
>
> Iso3166CountryLongitudeLatitude maps country codes to their average or central longtiude/latitude.
>
> My keys are two letter Iso3166 Symbols representing a country, such as #BE
> My values are Points holding coordinates as longtiude@latitude
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like BE,50.8333,4.0000 or code,latitude,longitude
>
> You can download a version of this file from http://homepage.mac.com/svc/data/CountryLatLong.csv.gz
>
> ((Iso3166CountryLongitudeLatitude readFrom: 'CountryLatLong.csv') at: #BE) = 4.0@50.8333
>
> You should cache one instance of me.
>
> ---
>
> Sven
>
>
>

--
Miguel Cobá
http://twitter.com/MiguelCobaMtz
http://miguel.leugim.com.mx




Reply | Threaded
Open this post in threaded view
|

Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Stéphane Ducasse
In reply to this post by Sven Van Caekenberghe
Sven

I would love to have your application in our success stories :)
do you have a simple paragraph?

Stef

On Apr 4, 2011, at 3:21 PM, Sven Van Caekenberghe wrote:

> I want to share a couple of classes.
>
> Did you ever want to add this trick to your website where you do something based on the country your visitors are from ? Now you can do so in Smalltalk !
>
> T3EasyUtils getIpAddressCountry atAddress: '81.83.7.35'
>
> #BE
>
> T3EasyUtils getIso3166CountryLongitudeLatitude at: #BE
>
> 4.0@50.8333
>
> #('www.beta9.be' 'www.inria.fr' 'nic.st' 'www.world.st' 'www.pharo-project.org')
> collect: [ :each | T3EasyUtils getIpAddressCountry atAddress: (NetNameResolver addressForName: each) ]
>
> #(#BE #FR #SE #US #CH)
>
> (T3EasyUtils is holding unique, loaded instances of IPAddressCountry & Iso3166CountryLongitudeLatitude).
>
> As this is part of one of our commercial applications, you can even access it over the internet as a JSON REST call:
>
> $ curl http://easy.t3-platform.net/rest/geo-ip?address=81.83.7.35
>
> {"latitude":50.8333,"address":"81.83.7.35","country":"BE","longitude":4.0}
>
> (Please note that this is not a public service as such, you can try it, but you are not supposed to call this from your own applications.)
>
> BTW, T3 Easy is our new entry level track & trace product, an HTML5 web app (using client side HTML+Javascript+CSS) on top of a REST server written in Pharo Smalltalk. It consists of 4 stateless Pharo Cog VM's running behind an Apache load balancer. The server uses Zinc HTTP Components, both for its server part, as well as for clients talking to other systems behind the scenes. Even the Open Street Map tile serving, which is pushing out many megabytes, is currently going through this server.
>
> Here is a live demo URL in case your are curious:
>
> http://easy.t3-platform.net?t=livedemo
>
> (You need a fast web browser like Google Chrome, Safari, Opera 10 or Firefox 4.)
>
> The code for IPAddressCountry & Iso3166CountryLongitudeLatitude is on SqueakSource:
>
> http://www.squeaksource.com/ADayAtTheBeach.html
>
> These are the class comments:
>
> ---
>
> IPAddressCountry maps IP addresses to their country code.
> I hold a collection of IPAddressRangeCountry objects that I do a binary search on.
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like 3651886848,3651887103,BE or start,stop,code
>
> You can download a version of this file from http://homepage.mac.com/svc/data/GeoIPCountry.csv.gz
>
> ((IPAddressCountry readFrom: 'GeoIPCountry.csv') atAddress: '81.83.7.35') = #BE
>
> Addresses can also be specified as #(81 83 7 35) for #atAddress: or as 1364395811 for #at:
>
> You should cache one instance of me.
>
> Based on data from http://www.maxmind.com/app/geolitecountry
>
> ---
>
> Iso3166CountryLongitudeLatitude maps country codes to their average or central longtiude/latitude.
>
> My keys are two letter Iso3166 Symbols representing a country, such as #BE
> My values are Points holding coordinates as longtiude@latitude
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like BE,50.8333,4.0000 or code,latitude,longitude
>
> You can download a version of this file from http://homepage.mac.com/svc/data/CountryLatLong.csv.gz
>
> ((Iso3166CountryLongitudeLatitude readFrom: 'CountryLatLong.csv') at: #BE) = 4.0@50.8333
>
> You should cache one instance of me.
>
> ---
>
> Sven
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Mariano Martinez Peck
what is the license?

On Mon, Apr 4, 2011 at 5:44 PM, Stéphane Ducasse <[hidden email]> wrote:
Sven

I would love to have your application in our success stories :)
do you have a simple paragraph?

Stef

On Apr 4, 2011, at 3:21 PM, Sven Van Caekenberghe wrote:

> I want to share a couple of classes.
>
> Did you ever want to add this trick to your website where you do something based on the country your visitors are from ? Now you can do so in Smalltalk !
>
> T3EasyUtils getIpAddressCountry atAddress: '81.83.7.35'
>
>       #BE
>
> T3EasyUtils getIso3166CountryLongitudeLatitude at: #BE
>
>       4.0@50.8333
>
> #('www.beta9.be' 'www.inria.fr' 'nic.st' 'www.world.st' 'www.pharo-project.org')
>       collect: [ :each | T3EasyUtils getIpAddressCountry atAddress: (NetNameResolver addressForName: each) ]
>
>       #(#BE #FR #SE #US #CH)
>
> (T3EasyUtils is holding unique, loaded instances of IPAddressCountry & Iso3166CountryLongitudeLatitude).
>
> As this is part of one of our commercial applications, you can even access it over the internet as a JSON REST call:
>
> $ curl http://easy.t3-platform.net/rest/geo-ip?address=81.83.7.35
>
>       {"latitude":50.8333,"address":"81.83.7.35","country":"BE","longitude":4.0}
>
> (Please note that this is not a public service as such, you can try it, but you are not supposed to call this from your own applications.)
>
> BTW, T3 Easy is our new entry level track & trace product, an HTML5 web app (using client side HTML+Javascript+CSS) on top of a REST server written in Pharo Smalltalk. It consists of 4 stateless Pharo Cog VM's running behind an Apache load balancer. The server uses Zinc HTTP Components, both for its server part, as well as for clients talking to other systems behind the scenes. Even the Open Street Map tile serving, which is pushing out many megabytes, is currently going through this server.
>
> Here is a live demo URL in case your are curious:
>
>       http://easy.t3-platform.net?t=livedemo
>
> (You need a fast web browser like Google Chrome, Safari, Opera 10 or Firefox 4.)
>
> The code for IPAddressCountry & Iso3166CountryLongitudeLatitude is on SqueakSource:
>
>       http://www.squeaksource.com/ADayAtTheBeach.html
>
> These are the class comments:
>
> ---
>
> IPAddressCountry maps IP addresses to their country code.
> I hold a collection of IPAddressRangeCountry objects that I do a binary search on.
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like 3651886848,3651887103,BE or start,stop,code
>
> You can download a version of this file from http://homepage.mac.com/svc/data/GeoIPCountry.csv.gz
>
> ((IPAddressCountry readFrom: 'GeoIPCountry.csv') atAddress: '81.83.7.35') = #BE
>
> Addresses can also be specified as #(81 83 7 35) for #atAddress: or as 1364395811 for #at:
>
> You should cache one instance of me.
>
> Based on data from http://www.maxmind.com/app/geolitecountry
>
> ---
>
> Iso3166CountryLongitudeLatitude maps country codes to their average or central longtiude/latitude.
>
> My keys are two letter Iso3166 Symbols representing a country, such as #BE
> My values are Points holding coordinates as longtiude@latitude
>
> I am constructed based on a CSV data file using my class' #readFrom:
> which expects lines like BE,50.8333,4.0000 or code,latitude,longitude
>
> You can download a version of this file from http://homepage.mac.com/svc/data/CountryLatLong.csv.gz
>
> ((Iso3166CountryLongitudeLatitude readFrom: 'CountryLatLong.csv') at: #BE) = 4.0@50.8333
>
> You should cache one instance of me.
>
> ---
>
> Sven
>
>
>





--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Sven Van Caekenberghe

On 04 Apr 2011, at 18:42, Mariano Martinez Peck wrote:

> what is the license?

I'll explicitely MIT license those 3 classes involved as the repo has no specific license.

Sven


Reply | Threaded
Open this post in threaded view
|

Re: [SPAM] Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Sven Van Caekenberghe
In reply to this post by Stéphane Ducasse

On 04 Apr 2011, at 17:44, Stéphane Ducasse wrote:

> I would love to have your application in our success stories :)
> do you have a simple paragraph?

I will be adding more stuff in the coming months, after that things will be closer to a 'success story' than today, this is just a first step.

Sven



Reply | Threaded
Open this post in threaded view
|

Re: IPAddressCountry & Iso3166CountryLongitudeLatitude

Sven Van Caekenberghe
In reply to this post by Henrik Sperre Johansen

On 04 Apr 2011, at 15:45, Henrik Johansen wrote:

> PS. I take it you'd be interested in updating SmallInteger digitAt: / digitLength to work in 64bit images if they become available? ;)

I am not quite sure what you mean.

The particular server this application is running on is a quite plain vanilla Dual Core Xeon (4 virtual CPU's @ 3Ghz, 4 GB RAM) running Ubuntu 8.04.4 LTS 64-bit Server edition, shared with some other applications, one taking 2Gb. The server has a high quality internet feed.

The Cog VM's can only use 1 core and are 32-bit as far as I know. Running 4 of them better utilizes the machine. Monit, automatic process management, keeps the instances alive. The load balancer + the process management should improve reliability and scalebility under load.

Each instance uses less than 100 Mb for its heap, so there is plenty of room left. In terms of addressing space, I don't need more.

Granted, representing IPv4 addresses as Integers requires 32 bits, and results in LargePositiveInteger usage. So a 64-bit VM could be better. But honestly, searching through 140.000 entries using binary search is currently very fast already.

To give you an idea, for the full stack over the internet (and thus depending on the network, YMMV) :

$ ab -k -n 1024 -c 32 http://easy.t3-platform.net/rest/geo-ip?address=81.83.7.35

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking easy.t3-platform.net (be patient)
Completed 102 requests
Completed 204 requests
Completed 306 requests
Completed 408 requests
Completed 510 requests
Completed 612 requests
Completed 714 requests
Completed 816 requests
Completed 918 requests
Completed 1020 requests
Finished 1024 requests


Server Software:        Zinc
Server Hostname:        easy.t3-platform.net
Server Port:            80

Document Path:          /rest/geo-ip?address=81.83.7.35
Document Length:        76 bytes

Concurrency Level:      32
Time taken for tests:   1.118 seconds
Complete requests:      1024
Failed requests:        0
Write errors:           0
Keep-Alive requests:    1024
Total transferred:      312657 bytes
HTML transferred:       77900 bytes
Requests per second:    915.75 [#/sec] (mean)
Time per request:       34.944 [ms] (mean)
Time per request:       1.092 [ms] (mean, across all concurrent requests)
Transfer rate:          273.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   4.8      0      32
Processing:    21   34   7.9     32      76
Waiting:       21   34   7.9     32      76
Total:         21   34   9.6     32     109

Percentage of the requests served within a certain time (ms)
  50%     32
  66%     36
  75%     38
  80%     40
  90%     45
  95%     54
  98%     64
  99%     70
 100%    109 (longest request)


This means that for 32 concurrent requests, speed is close to 1000 request per second, or 1 ms per request. (Granted the payload is small and keepalive is involved).

For me, this means that one can do almost anything with a Smalltalk server. And that is the main point I want to make and share.

Regards,

Sven