How to Detect VPNs and Proxies in Python/Node.js in Under 20ms
The Problem
Whether you are running a streaming service with region rights, a SaaS offering with free tiers, or an e-commerce platform, anonymous traffic is a headache. Users use VPNs to bypass geo-blocks, and bad actors use residential proxies to abuse sign-up bonuses or scrape your data.
The challenge isn't just detecting them—it's detecting them fast. Adding latency to your signup or checkout flow kills conversion rates. You need an answer in milliseconds, not seconds.
The "Hard" Way
The traditional approach is to maintain your own list of IP ranges. You might download public blocklists, subscribe to MaxMind's database updates, or scrape known proxy lists.
This fails for two reasons:
- Velocity: VPN providers rotate IPs daily. A static database downloaded on Monday is stale by Tuesday.
- Complexity: Hosting and querying a massive MMDB file requires infrastructure, memory, and regular maintenance scripts.
The "Easy" Way (IPASIS)
The modern approach is to offload this complexity to a real-time API. IPASIS aggregates threat feeds, behavioral analysis, and live network telemetry to give you a definitive answer instantly.
Here is how to implement a check in Python and Node.js.
Python Example
Node.js Example
The Logic
The logic is refreshingly simple. The API returns a privacy object with boolean flags. You don't need to parse complex scores or probability weights unless you want to.
// The API response structure
{
"privacy": {
"VPN": true, // Commercial VPN detected
"Proxy": false, // Public/Web proxy
"Tor": false, // Tor exit node
"Hosting": true // Datacenter/Hosting provider
}
}If VPN, Proxy, or Tor is true, you can block the request, require 2FA, or show a CAPTCHA. It's deterministic and easy to reason about.