Vendredi 23 novembre 2018

Géolocalisation

ipinfo.io

http://ipinfo.io/
Try our JSON API from the command line.

curl ipinfo.io
{
  "ip": "185.159.158.50",
  "city": "Plan-les-ouates",
  "region": "Geneve",
  "country": "CH",
  "loc": "46.1676,6.1191",
  "postal": "1228",
  "org": "AS56704 Farice ehf"
}
curl ipinfo.io/8.8.8.8
{
    "ip": "8.8.8.8",
    "hostname": "google-public-dns-a.google.com",
    "city": "Mountain View",
    "region": "California",
    "country": "US",
    "loc": "37.3860,-122.0838",
    "org": "AS15169 Google Inc.",
    "postal": "94040"
}
curl ipinfo.io/8.8.8.8/org
AS15169 Google Inc.

iplocality.com

https://iplocality.com

curl iplocality.com
{
    "ip": "185.159.158.50",
    "country": "Iceland",
    "country_code": "IS",
    "region": "Hofudborgarsvaedi utan Reykjavikur",
    "city": "Reykjavik",
    "latitude": "64.13548",
    "longitude": "-21.89541",
    "zip_code": "108",
    "time_zone": "+00:00"

DB-IP

Données affichées avec “API key free (fourni sur simple adresse mail)”:

  • Country
  • State/Province
  • City
  • 2500 requêtes/Jour

API Documentation

The DB-IP API is exposed via RESTful web services.

In order to get an answer, you need to build a valid request URL of the following form : http://api.db-ip.com/<methodname>?<parameters>

The parameters depend on the called method, but they must always include an “api_key” element with a value equal to your API key.

The following methods are available to API clients :

    addrinfo : Lookup IP address information
    keyinfo : Get API key information

Method: addrinfo

Lookup IP address information

Method addrinfo takes two parameters :

addr       The IPv4 or IPv6 address to look up
api_key    Your API key

Here is a sample URL for calling addrinfo : http://api.db-ip.com/addrinfo?addr=173.194.67.1&api_key=123456789

The server responds with a JSON encoded object with some or all of the following properties :

address    	The requested IP address
country    	Two-letters country code (ISO 3166-1 alpha-2)
stateprov  	Name of state or province
city       	City name
latitude   	Decimal latitude
longitude  	Decimal longitude
tz_offset  	Offset from UTC in hours
tz_name    	Name of timezone
isp        	Internet Service Provider name
ctype      	Connection type
organization    Organization name

Sample response using a Lite API Key :

{
"address": "173.194.67.1",
"country": "US",
"stateprov": "California",
"city": "Mountain View",
"latitude": "37.422",
"longitude": "-122.085",
"tz_offset": "-7",
"tz_name": "America/Los_Angeles"
}

Sample response using a Pro API Key :

{
"address": "173.194.67.1",
"country": "US",
"stateprov": "California",
"city": "Mountain View",
"latitude": "37.422",
"longitude": "-122.085",
"tz_offset": "-7",
"tz_name": "America/Los_Angeles",
"isp": "Google Inc.",
"ctype": "fttx",
"organization": "Google Inc.",
}

If an error occured, the server responds with an object containing only an error property with the actual error text :

{ "error": "invalid API key" }

Method: keyinfo

Get API key information

Method keyinfo takes one parameter :

api_key    Your API key

Here is a sample URL for calling keyinfo : http://api.db-ip.com/keyinfo?api_key=123456789

The server responds with a JSON encoded object with some or all of the following properties :

api_key		    Your API key
queries_per_day	    Numbers of IP address queries per day allowed by your API key
queries_left	    Number of IP address queries left for the day
expires		    You API key expiration date and time (format is YYYY-MM-DD HH:MM:SS and timezone is UTC)

Sample response :

{
"api_key": "my_test_key",
"queries_per_day": "10000",
"queries_left": "2863",
"expires": "2016-12-31 09:44:42"
}

<WRAP center round download 60%> PHP source code

This package contains the core DB-IP API Client class, and sample lookup code : dbip-api-phpsrc-1.0.tgz </WRAP>

MaxMind

Les bases de données
GeoLiteCountry
Index of /mirror/ip_database/current (ipinfodb_one_table_full.sql.bz2)

Se rendre sous le répertoire de téléchargement
Décompresser le fichier
Charger les données dans la base MySql

	:::bash
	$ cd /media/dplus/telechargement
	$ bunzip2 -v ipinfodb_one_table_full.sql.bz2
	  ipinfodb_one_table_full.sql.bz2: done

Créer une base geoip avec phpmyadmin pour y intégrer les données du fichier sql

	:::bash
	$ mysql -uutilisateur -pmot_passe geoip < ipinfodb_one_table_full.sql

Ouvrir la base geoip , lister les structures

	:::bash
	$ mysql -uutilisateur -pmot_passe geoip
	mysql> show tables;
	+------------------+
	| Tables_in_geoip  |
	+------------------+
	| ip_group_city    | 
	| ip_group_country | 
	+------------------+
	2 rows in set (0.00 sec)
	
	mysql> show fields from ip_group_city;
	+--------------+-------------+------+-----+---------+-------+
	| Field        | Type        | Null | Key | Default | Extra |
	+--------------+-------------+------+-----+---------+-------+
	| ip_start     | bigint(20)  | NO   | PRI | NULL    |       | 
	| country_code | varchar(2)  | NO   |     | NULL    |       | 
	| country_name | varchar(64) | NO   |     | NULL    |       | 
	| region_code  | varchar(2)  | NO   |     | NULL    |       | 
	| region_name  | varchar(64) | NO   |     | NULL    |       | 
	| city         | varchar(64) | NO   |     | NULL    |       | 
	| zipcode      | varchar(6)  | NO   |     | NULL    |       | 
	| latitude     | float       | NO   |     | NULL    |       | 
	| longitude    | float       | NO   |     | NULL    |       | 
	| timezone     | varchar(4)  | NO   |     | NULL    |       | 
	| gmtOffset    | varchar(4)  | NO   |     | NULL    |       | 
	| dstOffset    | varchar(4)  | NO   |     | NULL    |       | 
	+--------------+-------------+------+-----+---------+-------+
	12 rows in set (0.00 sec)
	
	mysql> show fields from ip_group_country;
	+--------------+-------------+------+-----+---------+-------+
	| Field        | Type        | Null | Key | Default | Extra |
	+--------------+-------------+------+-----+---------+-------+
	| ip_start     | bigint(20)  | NO   | PRI | NULL    |       | 
	| ip_cidr      | varchar(20) | NO   |     | NULL    |       | 
	| country_code | varchar(2)  | NO   | MUL | NULL    |       | 
	| country_name | varchar(64) | NO   |     | NULL    |       | 
	+--------------+-------------+------+-----+---------+-------+
	4 rows in set (0.00 sec)
	
	mysql> select ip_start,country_code,country_name,city,latitude,longitude
	    -> FROM `ip_group_city` 
	    -> WHERE `ip_start` <= INET_ATON('88.140.21.214') 
	    -> ORDER BY ip_start DESC LIMIT 1;
	+------------+--------------+--------------+---------+----------+-----------+
	| ip_start   | country_code | country_name | city    | latitude | longitude |
	+------------+--------------+--------------+---------+----------+-----------+
	| 1485575168 | FR           | France       | Feytiat |     45.8 |    1.3333 | 
	+------------+--------------+--------------+---------+----------+-----------+
	1 row in set (0.00 sec)
	

Winaero

Winaero
Obtenez des informations sur la géolocalisation de l’adresse IP dans Bash sous Linux.

Parfois, vous avez besoin d’obtenir rapidement les informations de géolocalisation d’une adresse IP. Sous Linux, vous pouvez utiliser la puissance des applications de la console pour gagner du temps et récupérer ces informations rapidement. Voyons comment cela peut être fait.

Pour obtenir les informations de localisation géographique d’une adresse IP spécifique, vous devez utiliser un service en ligne qui fournit l’API appropriée. C’est une bonne idée d’utiliser un service public pour éviter la procédure d’autorisation et la gestion des clés de l’API. L’un de ces services est FreeGeoIP.net.

Il fournit une API HTTP publique pour rechercher la géolocalisation des adresses IP. Il utilise une base de données d’adresses IP associées aux villes ainsi que d’autres informations pertinentes comme le fuseau horaire, la latitude et la longitude.

Le service peut fournir des résultats de recherche sous forme de JSON ou XML. Ainsi, si nous combinons le curl avec un analyseur JSON, nous pouvons obtenir les informations requises.

curl freegeoip.net/json/185.159.158.101
{"ip":"185.159.158.101","country_code":"IS","country_name":"Iceland","region_code":"1","region_name":"Capital Region","city":"Reykjavik","zip_code":"105","time_zone":"Atlantic/Reykjavik","latitude":64.136,"longitude":-21.9203,"metro_code":0}

Pour une extraction directe

curl -s freegeoip.net/json/185.159.158.101 | jq -r '.country_name,.latitude,.longitude'
Iceland
64.136
-21.9203

Pour le traitement, il vaut mieux mettre les informations au format json dans une variable

freegeoip=$(curl -s freegeoip.net/json/185.159.158.101)

Extraction des informations

echo $freegeoip | jq -r '.city'
   Reykjavik
echo $freegeoip | jq -r '.country_name,.latitude,.longitude'
Iceland
64.136
-21.9203

Voir LINUX Magazine/France HORS-SERIE N°46 page 8