https://github.com/oselya/ip-geolocation-bundle
Symfony IP geolocation bundle
https://github.com/oselya/ip-geolocation-bundle
geolocation ip ipapi ipv4 ipv6 maxmind symfony-bundle
Last synced: 6 months ago
JSON representation
Symfony IP geolocation bundle
- Host: GitHub
- URL: https://github.com/oselya/ip-geolocation-bundle
- Owner: oselya
- License: mit
- Created: 2022-04-23T06:11:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T12:25:13.000Z (over 1 year ago)
- Last Synced: 2025-04-13T05:08:46.963Z (11 months ago)
- Topics: geolocation, ip, ipapi, ipv4, ipv6, maxmind, symfony-bundle
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Symfony IP geolocation bundle
=============================
[![License][license-image]][license-link] 
Install
```shell
composer req oselya/ip-geolocation-bundle
```
Before we get started, there is a small amount of configuration needed
```yml
# app/config/ip_geolocation.yaml
ip_geolocation:
cache_ttl: -1
maxmind:
city_path: 'GeoLite2-City.mmdb'
ip_api_com:
access_key: 'qwerty'
```
Cli command
```shell
$ bin/console app:ip:location 92.253.204.162
+----------------+-----------+---------+-----------------+-----------------+
| IP | Continent | Country | Latitude | Longitude |
+----------------+-----------+---------+-----------------+-----------------+
| 92.253.204.162 | EU | UA | 48.342449188232 | 24.575370788574 |
+----------------+-----------+---------+-----------------+-----------------+
```
Service
```php
setName('app:ip:location')
->addArgument('ip', InputArgument::REQUIRED, 'The IP address.')
->setDescription('This command allows you to lookup location of IP addresses.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$location = $this->provider->ipLookup(new Ip($input->getArgument('ip')));
$table = new Table($output);
$table
->setHeaders(['IP', 'Continent', 'Country', 'Latitude', 'Longitude'])
->setRows([
[
$input->getArgument('ip'),
$location->getContinent(),
$location->getCountry(),
$location->getLatitude(),
$location->getLongitude(),
],
]);
$table->render();
return Command::SUCCESS;
}
}
```
[license-link]: https://github.com/oselya/ip-geolocation-bundle/blob/main/LICENSE
[license-image]: https://img.shields.io/dub/l/vibe-d.svg