Download the PHP package vpndetector/laravel-vpn-detector without Composer
On this page you can find all versions of the php package vpndetector/laravel-vpn-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vpndetector/laravel-vpn-detector
More information about vpndetector/laravel-vpn-detector
Files in vpndetector/laravel-vpn-detector
Package laravel-vpn-detector
Short Description VPN, proxy and Tor detection middleware for Laravel, powered by the IP2Proxy database.
License MIT
Informations about the package laravel-vpn-detector
🛡️ Laravel VPN Detector
Block VPN, proxy, and Tor traffic in your Laravel application — powered by the IP2Proxy PX2 database.
What it does
Laravel VPN Detector looks up every incoming request's IP address against a local copy of the IP2Proxy database and can:
- Block requests from VPN, public proxy, web proxy, or Tor nodes via a drop-in middleware
- Force a logout when an authenticated user switches to a Tor exit node mid-session
- Keep the database fresh automatically with a built-in Artisan command and scheduler integration
All lookups are done in-process against your own database — no external API calls at runtime, no latency overhead.
How it works
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.3 |
| Laravel | ^12.0 |
| MySQL / MariaDB | Any version supporting INET_ATON / INET6_ATON |
| IP2Proxy account | Free tier works (PX2 database) |
Installation
1. Install via Composer
2. Publish config and migrations
3. Set your IP2Proxy token
Add your download token to .env (get it at ip2location.com):
4. Import the database
This downloads the PX2 CSV files from IP2Proxy (~300 MB each), extracts them, and bulk-imports them into the two database tables. Expect it to take 2–5 minutes on first run.
Architecture
The package is built around three layers:
IpLookupResult DTO is returned by checkProxyType() instead of raw stdClass, giving you typed, expressive access to the result:
The VpnDetector Facade provides a clean static interface:
Configuration
After publishing, config/vpn-detector.php exposes:
Full list of .env keys: see .env.example.
Usage
Middleware — block VPN/proxy users
Register BlockVpnMiddleware on any route or group:
Blocked requests receive a 403 Access via VPN or proxy is not permitted. response.
Action — force-logout Tor users
Use CheckVpnBlocked in your own middleware or controller when you want finer control (e.g. only log out authenticated Tor users):
The IP is cached in the session so the database is only queried once per unique IP per session.
Service — direct injection
Inject VpnDetectionService (or its interface) anywhere:
Scheduler — keep the database fresh
Add SchedulesVpnDetector to your console kernel to automatically refresh the IP2Proxy data:
Database tables
The package creates two tables populated from the IP2Proxy PX2 dataset:
| Column | Type | Description |
|---|---|---|
ip_from |
decimal(39,0) | Start of IP range (integer representation) |
ip_to |
decimal(39,0) | End of IP range |
proxy_type |
varchar(3) | VPN, TOR, PUB, WEB, - |
country_code |
char(2) | ISO 3166-1 alpha-2 |
country_name |
varchar(64) | Full country name |
Both ip_from and ip_to form a composite primary key, allowing efficient range lookups via INET_ATON / INET6_ATON.
Note: IP2Proxy recommends using the IPv6 table for both IPv4 and IPv6 queries, but coverage is incomplete in practice. This package queries both tables, routing by address family.
Benchmark
The package ships with a self-contained benchmark command. It generates 6 000 000 synthetic rows (3M IPv4 + 3M IPv6) into a temporary SQLite file, then measures lookup latency — no real IP2Proxy database or API token required.
Example output (AMD Ryzen 7, SQLite — MySQL with proper indexes will be significantly faster):
These numbers use SQLite as the backend. Production MySQL/MariaDB with a real IP2Proxy dataset and proper indexes will have lower raw lookup latency; the cache speedup ratio (~20 000x) holds regardless of the database engine.