Download the PHP package suprun-bohdan/laravel-ip-info without Composer
On this page you can find all versions of the php package suprun-bohdan/laravel-ip-info. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download suprun-bohdan/laravel-ip-info
More information about suprun-bohdan/laravel-ip-info
Files in suprun-bohdan/laravel-ip-info
Package laravel-ip-info
Short Description Laravel package for IP detection, normalization, request IP resolution, geo lookup, caching, and infrastructure-aware IP intelligence.
License MIT
Homepage https://github.com/suprun-bohdan/laravel-ip-info
Informations about the package laravel-ip-info
Laravel IP Info
Laravel package for smart IP resolution, geo lookup, and cache-first IP intelligence — trusted proxies, provider chains, offline MMDB (IPv4 + IPv6), middleware, and testing fakes.
Author: Bohdan Suprun
Quick Start
After install, public IP lookups work immediately via the HTTP provider (quick_start preset).
For production, prefer offline geo — no rate limits, no outbound HTTP:
See Offline geo guide for country vs city editions and IPv6.
Production behind Cloudflare
Add to .env:
Register client IP resolution (opt-in):
Route middleware (v4.2+)
| Alias | Class | Purpose |
|---|---|---|
ip.resolve |
ResolveClientIp |
Sets ip_info / client_ip on request |
geo.block |
BlockCountries |
Block by country (geo.block:RU,BY) |
geo.allow |
AllowCountries |
Allow-list only |
geo.share |
ShareClientGeo |
API/Inertia geo payload |
ip.log |
LogClientIp |
Structured client IP logging (v4.3+) |
ip.filter |
FilterClientIp |
Block Tor/proxy/WHOIS rules (v4.3+) |
IP intelligence (v4.3+)
Live WHOIS (IANA → RIR, TCP :43), threat signals, privacy profile, and optional request logging:
Key env vars: IP_INFO_WHOIS_ENABLED, IP_INFO_CLIENT_LOG_ENABLED, IP_INFO_FILTERING_ENABLED, IP_INFO_TOR_EXIT_CIDRS.
IP risk and filtering (v4.5+)
Per-reason HTTP responses, risk scoring, block events, and verified crawler bypass:
Config (config/ip-info.php):
Listen for blocks:
Blade: @highrisk … @endhighrisk wraps content when risk level is high.
Blade (v4.4+)
Directives
@geoblock('RU') aborts when the client matches (uses ip-info.security.* config). For middleware-level filtering use ip.filter instead of duplicating abort logic in Blade.
Dev components (local / staging)
Publish CSS and optional view overrides:
In your layout:
| Component | Purpose |
|---|---|
<x-ip-info::dev-banner /> |
Country, continent, EU badge, anonymized IP, privacy/threat chips |
<x-ip-info::country-gate countries="UA,PL"> |
Slot content when client country matches; optional fallback slot |
<x-ip-info::debug-panel /> |
Collapsible <details> dump of geo, privacy, threats (no WHOIS) |
Props: dev-banner — showIp, showThreats, onlyPrivate; debug-panel — collapsed (default true).
Components use ClientGeoData and ip_info()->threats() only — no live WHOIS in views.
Helpers reference (v4.2+)
| Function / macro | Returns | Notes |
|---|---|---|
ip_info(?string $ip = null) |
IpInfoQuery |
Current request when $ip omitted |
client_country(?Request $r = null, ?string $default = null) |
?string |
Uses request memo + cache |
client_city(?Request $r = null, ?string $default = null) |
?string |
City from offline MMDB (v4.6+) |
client_asn(?Request $r = null, ?int $default = null) |
?int |
ASN from offline enrichment (v4.7+) |
client_ip(?Request $r = null) |
string |
Reuses middleware attribute when set |
client_ip_info(?Request $r = null) |
IpInfoResult |
Full DTO |
normalize_ip(string $ip) |
string |
Canonical IP (v4.3+) |
ip_privacy(?string $ip = null) |
IpPrivacyProfile |
Private/public/reserved (v4.3+) |
ip_threats(?string $ip = null) |
IpThreatSignals |
Tor/proxy/VPN/hosting (v4.3+) |
client_ip_intel(?Request $r = null, bool $withWhois = false) |
ClientIpIntel |
Geo + privacy + threats + WHOIS (v4.3+) |
client_ip_risk(?Request $r = null) |
ClientIpRiskScore |
Weighted risk score (v4.5+) |
is_verified_crawler(?string $ip = null) |
bool |
Reverse DNS verified bot (v4.5+) |
whois_lookup(string $ip, bool $force = false) |
?WhoisRecord |
Live WHOIS lookup (v4.3+) |
request()->clientCountry() |
?string |
Macro |
request()->clientCity() |
?string |
Macro (v4.6+) |
request()->ipInfo() |
IpInfoResult |
Macro |
request()->clientIpRisk() |
ClientIpRiskScore |
Macro (v4.5+) |
request()->isVerifiedCrawler() |
bool |
Macro (v4.5+) |
request()->isCountry('UA', ...) |
bool |
Macro |
Fluent on IpInfoQuery / IpInfoResult: isCountry(), inCountries(), isEu(), countryOr(), countryOrFail(), city(), region(), timezone(), coordinates() (v4.6+).
Choosing a geo provider
The package tries providers in order (providers.chain). First hit wins.
| Provider | Data | IPv6 | HTTP | Best for |
|---|---|---|---|---|
local |
Built-in private/reserved rules | Yes | No | Always first — skips lookup for LAN IPs |
location_db (v4.6+) |
Country or city MMDB | Yes | No | Recommended production offline |
database |
Legacy CSV → ip_country table |
No | No | Existing installs, IPv4 country only |
maxmind |
GeoLite2 MMDB | Yes | No | Teams with MaxMind license |
http |
ipinfo / ip-api | Yes | Yes | Dev / quick start |
cleantalk |
CleanTalk API | Varies | Yes | Optional enrichment |
New projects: use location_db with --preset=offline.
Legacy projects: keep database enabled; add location_db ahead of it in the chain for IPv6 and city.
Performance and cache-first design
Lookups are cache-first: request memo → Laravel cache (positive + negative TTL) → provider chain. Private IPs never hit external providers.
| Path | Typical latency |
|---|---|
| Cache hit (same country code) | ~0.03 ms |
Offline MMDB (location_db) |
~0.1 ms |
HTTP provider (quick_start) |
50–500+ ms |
Measure in your environment:
User guide: bench/README.md
v4.7+: Cache v2 (
:v2:keys) stores a JSON geo payload — city, region, timezone, and ASN survive cache hits when enabled viaIP_INFO_CACHE_STORE_GEO_FIELDS=true(default). Fields respect thelocation_db.fieldswhitelist.
Security model (client IP)
- Never trust
X-Forwarded-Forblindly. Headers are read only when the remote address matchestrusted_proxies.proxy_cidrs, unlessrequire_trusted_proxy_for_headers=false. - Mirror Laravel
TrustProxieswhen usingrespect_laravel=true(default). - Cloudflare presets require
IP_INFO_TRUSTED_PROXY_CIDRS. Refresh withip-info:refresh-cloudflare-cidrs. - Runtime presets —
IP_INFO_PRESET=cloudflare|nginx_proxy|offline|quick_start|local_only(merged on each boot). - HTTP providers use HTTPS by default. Insecure
http://URLs requireIP_INFO_HTTP_ALLOW_INSECURE=true.
Testing
IpInfo::fake() bypasses positive/negative cache and skips cache writes during tests.
Benchmarks and stress
Full guide: bench/README.md
Docker verification
Run the full package suite and an ephemeral Laravel 11 app (path repo) inside Docker:
Micro-benchmarks without Docker:
No demo app is committed to the repository; docker/verify.sh and docker/stress.sh bootstrap a temporary app in a Docker volume.
What this package does
- Normalizes and validates IPv4/IPv6 input.
- Classifies public, private, localhost, link-local, and reserved addresses.
- Resolves client IP from HTTP requests with trusted-proxy awareness.
- Looks up country codes through a provider chain (
local,location_db,database,maxmind,http,cleantalk). - Offline city, region, timezone, and coordinates via MMDB (
location_db, v4.6+). - Caches lookups with configurable positive and negative TTL (cache-first).
- Built-in benchmarks and Docker stress tests for cache, MMDB, and HTTP paths.
- Geo block/allow middleware, validation rules, sync/diagnose tooling.
Requirements
- PHP ^8.2
- Laravel ^10, ^11, or ^12
- Laravel cache (array, file, redis, etc.)
- Database optional (legacy offline IPv4 CSV lookup)
maxmind-db/readeroptional (MaxMind GeoLite2 and ip-location-db MMDB)
Installation options
Publish configuration only:
Offline geo without HTTP (v4.6+)
Full user guide: docs/offline-geo.md
Download DB-IP Lite MMDB files via sapics/ip-location-db (CC BY 4.0 — attribute db-ip.com when displaying geo data to users).
Limit returned fields in config/ip-info.php → location_db.fields (whitelist at lookup time).
Legacy IPv4 CSV (still supported, separate from MMDB):
Optional MaxMind GeoLite2:
Application sync
--fix performs safe actions only: publish missing stubs and migrate. Middleware registration and schedule stubs require explicit flags.
When routes are enabled:
Configuration
File: config/ip-info.php
| Section | Purpose |
|---|---|
active_preset / IP_INFO_PRESET |
Runtime preset merge (cloudflare, offline, quick_start, …) |
cache |
TTL, negative cache, prefix, tenant prefix |
providers.chain |
Provider order |
presets |
Named proxy/provider bundles |
security |
Blocked/allowed countries, response status/message |
database |
Legacy offline IPv4 CSV (ip_country table) |
location_db |
Offline MMDB — edition, path, field whitelist (v4.6+) |
maxmind |
GeoLite2 MMDB path and license key |
http |
Driver (ipinfo, ip-api), HTTPS enforcement |
trusted_proxies |
Header allowlist, proxy CIDRs |
routes |
Opt-in API endpoint |
privacy |
Logging policy via IpPrivacyPolicy |
Commands
| Command | Description |
|---|---|
ip-info:install |
Publish config, migrate, optional preset |
ip-info:install --quick |
Enable HTTP geo (quick_start preset) |
ip-info:install --register-middleware |
Register ResolveClientIp (opt-in) |
ip-info:install --with-schedule |
Append update stubs to routes/console.php |
ip-info:install --with-location-db |
Download country MMDB (IPv4 + IPv6) |
ip-info:install --with-location-db=city |
Download city MMDB edition |
ip-info:install --with-location-db=asn_country |
Download ASN-country MMDB (CC0, v4.7+) |
ip-info:install --with-asn-db |
Download ASN enrichment MMDB (v4.7+) |
ip-info:install --preset=offline |
Chain without HTTP (location_db) |
ip-info:refresh-cloudflare-cidrs |
Fetch Cloudflare egress CIDRs for .env |
ip-info:sync |
Audit integration (config, middleware, routes, security) |
ip-info:diagnose |
Provider health + optional IP lookup |
ip-info:about |
Capability matrix (preset, helpers, aliases) |
ip-info:starter |
Publish middleware + install bundle |
ip-info:update-database |
Refresh offline IPv4 CSV |
ip-info:update-location-db |
Download ip-location-db MMDB files |
ip-info:update-maxmind |
Download GeoLite2 MMDB (--edition=country\|city\|asn) |
composer bench |
Run cache + MMDB micro-benchmarks |
make docker-stress |
Benchmarks + HTTP wrk stress (Docker) |
Architecture
| Layer | Role |
|---|---|
IpInfoManager |
Orchestration, cache, events, fake mode |
IpProviderResolver |
Injectable provider access |
ChainProvider |
Ordered providers; stops on hit/miss |
PresetConfigurator |
Runtime preset merge from .env |
IpCache |
Positive + negative TTL cache |
| Custom providers | providers.custom or IpInfoBuildingChain event |
Documentation
Public docs: docs/README.md
| Guide | Description |
|---|---|
| Offline geo | MMDB install, .env, city API, updates, troubleshooting (v4.6+) |
| Performance & benchmarks | Cache-first design, composer bench, make docker-stress |
| Migration guide | Upgrades and breaking changes |
| vs alternatives | Comparison with other Laravel geo packages |
Development
Local Docker sandbox (gitignored): cd sandbox && make init && make test
License
MIT. See LICENSE.
All versions of laravel-ip-info with dependencies
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^2.0
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/cache Version ^10.0|^11.0|^12.0
illuminate/bus Version ^10.0|^11.0|^12.0