PHPackages                             tantacula/ip2country - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tantacula/ip2country

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tantacula/ip2country
====================

Laravel package to lookup the country associated with an IPv4 address (fork from the 'Smalldogs' repo)

1.1.0(11y ago)016BSD-2-ClausePHPPHP &gt;=5.4.0

Since Nov 20Pushed 8y agoCompare

[ Source](https://github.com/Tantacula/ip2country)[ Packagist](https://packagist.org/packages/tantacula/ip2country)[ RSS](/packages/tantacula-ip2country/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel Country Lookup by IP Address
====================================

[](#laravel-country-lookup-by-ip-address)

[![Downloads](https://camo.githubusercontent.com/881262f18ad6efc1a4832bf5cdc195a8a8525d2a839ba5aa8aa7069c7a8b58a3/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d616c6c646f67732f697032636f756e7472792e7376673f7374796c653d666c6174)](https://packagist.org/packages/smalldogs/ip2country)[![License](https://camo.githubusercontent.com/1477775d3a9578a00a95be113989a43275f8cd66879366afe7556f25aae72c45/687474703a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d627364322d626c75652e7376673f7374796c653d666c6174)](http://opensource.org/licenses/BSD-2-Clause)[![Version](https://camo.githubusercontent.com/1d87ea32c399c0d025f704b576763c635049fd2e22d7fa42a52b4321d166b21c/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f736d616c6c646f67732f697032636f756e7472792e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/1d87ea32c399c0d025f704b576763c635049fd2e22d7fa42a52b4321d166b21c/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f736d616c6c646f67732f697032636f756e7472792e7376673f7374796c653d666c6174)[![TravisCI](https://camo.githubusercontent.com/2d41358856bc0ab1ab3734707283e4091808a342c07030f7fb1130a66d6b9831/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f736d616c6c646f67732f697032636f756e7472792e7376673f7374796c653d666c6174)](https://travis-ci.org/smalldogs/ip2country)

Laravel package to lookup the country associated with an IPv4 address. Developed with an eye to keeping it as lightweight and lookups as fast as possible. Creates and populates a **local database** table, so there are **no external requests** being made during runtime.

This package includes GeoLite data created by MaxMind, available from [](http://www.maxmind.com). The updated free downloadable database is released the first Tuesday of each month. I'll attempt to ensure to update this package each time.

Current IP Mapping Table
------------------------

[](#current-ip-mapping-table)

Doesn't seem to change much from month to month. Current version was released by MaxMind `February 4, 2015`

How to Update Mapping DB Table
------------------------------

[](#how-to-update-mapping-db-table)

If you have already installed and setup the ip2country package, but want to update the IP database mappings. First, get the latest ip2country package.

```
composer update
```

or, to only update this pacakage

```
composer update smalldogs/ip2country
```

Then, update your database by running the new migration.

```
php artisan migrate --package="smalldogs/ip2country"
```

How to Install
--------------

[](#how-to-install)

##### 1. Require the package with composer.

[](#1-require-the-package-with-composer)

```
composer require "smalldogs/ip2country"
```

##### 2. Create and populate the database lookup table.

[](#2-create-and-populate-the-database-lookup-table)

```
php artisan migrate --package="smalldogs/ip2country"
```

##### 3. Add the service to your providers array in `app/config/app.php`

[](#3-add-the-service-to-your-providers-array-in-appconfigappphp)

```
'providers' => array(
        'Smalldogs\Ip2Country\Ip2CountryServiceProvider',
        //[...]
);
```

How to Use
----------

[](#how-to-use)

```
// Returns the 2 letter country code for the user, eg: 'US'
$myCountryCode = Ip2Country::get();

// Returns the full name of the country, eg: 'United States'
$myCountryName = Ip2Country::getFull();

// Get the country for someone other than user on the page
$someonesIpAddress = '192.168.0.1';
$someonesCountryCode = Ip2Country::get($someonesIpAddress);
```

Configuration
-------------

[](#configuration)

By default, if the IP address is not found in the lookup table, it will return 'US' as a country code, and 'United States' as a country name. You can customize this in the config.

```
php artisan config:publish smalldogs/ip2country
```

Then navigate to `app/config/packages/smalldogs/ip2country/config.php`.

```
return array(
    // If IP address is not found, what country is returned
    'default_country_code' => 'US',
    'default_country_name' => 'United States',

    // Since our data will change, at most, once a month. Cache the Ip lookup for a day
    // Default: 1 day. Set to 0 or null to disable.
    'cache_results' => 60 * 24
);
```

If you don't want anything returned if the IP address is not found, simply set each of these to `=> null`

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4240d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1346989?v=4)[Dmitriy Burlakov](/maintainers/Tantacula)[@Tantacula](https://github.com/Tantacula)

---

Top Contributors

[![brwnll](https://avatars.githubusercontent.com/u/445190?v=4)](https://github.com/brwnll "brwnll (32 commits)")[![lowiebenoot](https://avatars.githubusercontent.com/u/330765?v=4)](https://github.com/lowiebenoot "lowiebenoot (1 commits)")[![Tantacula](https://avatars.githubusercontent.com/u/1346989?v=4)](https://github.com/Tantacula "Tantacula (1 commits)")

---

Tags

laravelIPlocationcountryipv4geocodeip-addressgeolookupip-lookup

### Embed Badge

![Health badge](/badges/tantacula-ip2country/health.svg)

```
[![Health](https://phpackages.com/badges/tantacula-ip2country/health.svg)](https://phpackages.com/packages/tantacula-ip2country)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k8.2M84](/packages/stevebauman-location)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[spatie/geocoder

Geocoding addresses to coordinates

8425.0M19](/packages/spatie-geocoder)[hibit-dev/geodetect

Automatically detect user's geo data based on their IP address

2321.5k](/packages/hibit-dev-geodetect)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

19253.0k3](/packages/interaction-design-foundation-laravel-geoip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
