Skip to content
/ geoip Public

Returns the location of an IP address. Based on the ipinfodb.com web service.

License

Notifications You must be signed in to change notification settings

manifest/geoip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

==== GeoIP ================================================
Returns the location of an IP address. Based on the http://ipinfodb.com web service.
To use the service user must have a API key, you may get it free after registration: http://ipinfodb.com/register.php.

----- Usage -----------------------------------------------
--- Before using
You must start the daemon before calling any of the functions

1> geoip:start("API_key").
{ok, <0.44.0>}

--- Lookup geolocation
2> geoip:geolocation().
#response{
	ip = {95,30,242,238},
	status = "OK",
	country_code = "RU",
	country_name = "Russian Federation",
	region_code = 48,
	region_name = "Moscow City",
	city = "Moscow",
	zip_postal_code = undefined,
	latitude = 55.7522,
	longitude = 37.6156,
	...
}

or

3> geoip:geolocation({74, 125, 232, 17}).
#response{
	ip = {74,125,232,17},
	status = "OK",
	country_code = "US",         
	country_name = "United States",
	region_code = 6,
	region_name = "California",
	city = "Mountain View",
	zip_postal_code = 94043,
	latitude = 37.4192,
	longitude = -122.057,
	...
}

--- Country precision (faster)

4> geoip:geolocation(#options {precision=country}).                    
#response{
	ip = {2,95,9,156},
	status = "OK",
	country_code = "RU",
	country_name = "Russian Federation",
	...
}

or

5> geoip:geolocation({74, 125, 232, 17}, #options {precision=country}).
#response{
	ip = {74,125,232,17},
	status = "OK",
	country_code = "US",
	country_name = "United States",
	...
}

--- Add timezone data

6> geoip:geolocation(#options {timezone = true}).  
#response{
	ip = {2,95,9,156},
	status = "OK",
	country_code = "RU",
 	country_name = "Russian Federation",
	region_code = 48,
	region_name = "Moscow City",
	city = "Moscow",
	zip_postal_code = undefined,
	latitude = 55.7522,
	longitude = 37.6156,
	timezone = "Europe/Moscow",
	utc_offset = 10800,
	dst = false
}

or

7> geoip:geolocation({74,125,232,17}, #options {timezone = true}).
#response{
	ip = {74,125,232,17},
	status = "OK",
	country_code = "US",
	country_name = "United States",
	region_code = 6,
	region_name = "California",
	city = "Mountain View",
	zip_postal_code = 94043,
	latitude = 37.4192,
	longitude = -122.057,
	timezone = "America/Los_Angeles",
	utc_offset = -25200,
	dst = true
}

--- Lookup your IP address
8> geoip:ip().
{2,95,9,156}

----- Compile & test --------------------------------------
make
cd ebin
./test.escript API_key

----- Copyright -------------------------------------------
Copyright (c) 2010 Andrey Nesterov. See LICENSE for details.

About

Returns the location of an IP address. Based on the ipinfodb.com web service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages