Verified Commit e3fff5dd authored by Luc Didry's avatar Luc Didry
Browse files

🎉 — First commit. Working 🙂

parents
*swp
dbip-city-lite-latest.mmdb
vendor/*
Revision history for GeoIP Lookup
0.1 2022-03-29
- first version, working
- private and reserved IP addresses are filtered
- country flags are displayed next to the country name
This diff is collapsed.
# GeoIP lookup
Une simple page PHP pour voir les informations geoIP relatives Ă  une adresse IP.
## Installation
Vous aurez besoin de [`composer`](https://getcomposer.org/download/).
```
git clone https://framagit.org/framasoft/geoip-lookup
cd geoip-lookup
composer install
curl --remote-name https://dbip.mirror.framasoft.org/files/dbip-city-lite-latest.mmdb
```
Vérifiez que la base de données est valide :
```
curl -s https://dbip.mirror.framasoft.org/files/dbip-city-lite-latest.mmdb.sha512sum | sha512sum -c
```
## Mise à jour de la base de données
À mettre dans une tâche cron, une fois par mois après le 2 du mois :
```
mv dbip-city-lite-latest.mmdb dbip-city-lite-latest.mmdb.bak && \
curl --remote-name https://dbip.mirror.framasoft.org/files/dbip-city-lite-latest.mmdb && \
curl -s https://dbip.mirror.framasoft.org/files/dbip-city-lite-latest.mmdb.sha512sum | sha512sum -c && \
rm dbip-city-lite-latest.mmdb.bak || \
mv dbip-city-lite-latest.mmdb.bak dbip-city-lite-latest.mmdb
```
## Licence
Ce logiciel est diffusé sous les termes de la [licence Affero GPL v3](LICENSE).
La base de données de [DB-IP](https://db-ip.com/) utilisée est diffusée sous les termes de la [licence CC-BY](http://creativecommons.org/licenses/by/4.0/) et *mirrorée* par [Framasoft](https://framasoft.org) à l’adresse <https://dbip.mirror.framasoft.org/>.
La bibliothèque [MaxMind-DB-Reader-php](https://github.com/maxmind/MaxMind-DB-Reader-php) est diffusée sous les termes de la [licence Apache 2.0](https://github.com/maxmind/MaxMind-DB-Reader-php/blob/main/LICENSE).
{
"require": {
"maxmind-db/reader": "~1.0"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ccf38c391dd2003a7c8899a77fd6b1f4",
"packages": [
{
"name": "maxmind-db/reader",
"version": "v1.11.0",
"source": {
"type": "git",
"url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git",
"reference": "b1f3c0699525336d09cc5161a2861268d9f2ae5b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/b1f3c0699525336d09cc5161a2861268d9f2ae5b",
"reference": "b1f3c0699525336d09cc5161a2861268d9f2ae5b",
"shasum": ""
},
"require": {
"php": ">=7.2"
},
"conflict": {
"ext-maxminddb": "<1.10.1,>=2.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "3.*",
"php-coveralls/php-coveralls": "^2.1",
"phpstan/phpstan": "*",
"phpunit/phpcov": ">=6.0.0",
"phpunit/phpunit": ">=8.0.0,<10.0.0",
"squizlabs/php_codesniffer": "3.*"
},
"suggest": {
"ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
"ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
"ext-maxminddb": "A C-based database decoder that provides significantly faster lookups"
},
"type": "library",
"autoload": {
"psr-4": {
"MaxMind\\Db\\": "src/MaxMind/Db"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Gregory J. Oschwald",
"email": "goschwald@maxmind.com",
"homepage": "https://www.maxmind.com/"
}
],
"description": "MaxMind DB Reader API",
"homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php",
"keywords": [
"database",
"geoip",
"geoip2",
"geolocation",
"maxmind"
],
"support": {
"issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues",
"source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.11.0"
},
"time": "2021-10-18T15:23:10+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.2.0"
}
img/favicon.png

1.14 KB

img/icon.png

8.41 KB

<?php
require 'vendor/autoload.php';
use MaxMind\Db\Reader;
if (isset($_GET['ip'])) {
$ip = $_GET['ip'];
$ipclean = htmlspecialchars($ip);
if (filter_var($ip, FILTER_VALIDATE_IP)) {
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) {
$err = "Désolée, ".$ipclean." est une adresse IP privée.";
$description = $ipclean." : désolée, c’est une adresse IP privée.";
} else if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) {
$err = "Désolée, ".$ipclean." est une adresse IP réservée (RFC 6890).";
$description = $ipclean." : désolée, c’est une adresse IP réservée (RFC 6890).";
} else {
$reader = new Reader('dbip-city-lite-latest.mmdb');
$infos = $reader->get($ip);
$reader->close();
$country_code = $infos['country']['iso_code'];
$flag = mb_convert_encoding( '&#' . ( 127397 + ord( $country_code[0] ) ) . ';', 'UTF-8', 'HTML-ENTITIES') .
mb_convert_encoding( '&#' . ( 127397 + ord( $country_code[1] ) ) . ';', 'UTF-8', 'HTML-ENTITIES');
if ($infos != null) {
$description = $ipclean." : ".$infos['continent']['names']['fr'].'/'.$infos['country']['names']['fr'].' '.$flag.'/'.$infos['city']['names']['en'];
} else {
$err = "Désolée, pas d’information pour l’adresse".$ipclean.".";
$description = $ipclean." : désolée, pas d’information pour cette adresse";
}
}
} else {
$err = "Désolée, ".$ipclean." n’est pas une adresse IP valide.";
}
} else {
$description = "Pour voir les infos géographiques d’une adresse IP";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>FramIPLookup</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="shortcut icon" href="/img/favicon.png">
<link rel="icon" type="image/png" href="/img/favicon.png">
<link rel="apple-touch-icon" href="/img/icon.png">
<meta property="og:type" content="website">
<meta property="og:title" content="Framasoft IP Lookup">
<meta property="og:description" content="<?php echo $description ?>">
<meta property="og:url" content="https://iplookup.framasoft.org">
<meta property="og:image" content="https://iplookup.framasoft.org/img/icon.png">
<style>
body {
max-width: 640px;
margin: 10px auto 0 auto;
}
input {
max-width: 640px;
}
form {
line-height: 2em;
}
</style>
</head>
<body>
<?php if (isset($_GET['ip'])) {
if (isset($err)) {
echo "<p>$err</p>";
} else { ?>
<h1><?php echo $ipclean ?></h1>
<dl>
<dt>Continent :</dt>
<dd><?php echo $infos['continent']['names']['fr'] ?></dd>
<dt>Pays :</dt>
<dd><?php echo $infos['country']['names']['fr'].' '.$flag ?></dd>
<dt>Ville :</dt>
<dd><?php echo $infos['city']['names']['en'] ?></dd>
</dl>
<?php }
echo '<hr>';
} ?>
<form method="GET">
<label for="ip">Adresse IP Ă  rechercher</label>
<input type="text" name="ip" id="ip">
<input type="submit">
</form>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment