How to Detect VPN Users with an IP API
Detecting a VPN from an IP address means asking a reputation API what is known about that address - whether it sits in a commercial VPN provider's range, a hosting network, a known proxy, or a Tor exit - and acting on the flags and score it returns. Nothing lets you see a VPN client on the user's device, so everything below is inference from the address they arrived on, which is why your threshold matters more than any single flag.
Why Detect VPN Users?
VPN detection is one of the most common reasons developers reach for an IP intelligence API. The motivations vary by application, but the core problems are consistent: fraud prevention, geo-restriction enforcement, and account abuse mitigation.
Fraud prevention is the most urgent use case. When a user conceals their real location behind a VPN during checkout, you lose confidence in billing address verification. Fraudsters routinely stack a VPN with a stolen card and a fake billing address โ the VPN masks the geographic mismatch that would otherwise be an obvious red flag.
Geo-restriction enforcement matters for licensing compliance. Streaming services, sports rights holders, and software vendors with territory-based pricing need to know when a user is tunnelling from a restricted region. A VPN detection signal lets you apply the correct entitlement or present the appropriate message rather than silently serving the wrong content.
Account abuse is a subtler problem. Credential stuffers and account farmers use VPNs to distribute login attempts across many exit IPs, defeating IP-based rate limiting. Detecting that a login attempt is originating from a VPN datacenter lets you apply tighter rate limits or trigger a step-up authentication challenge.
How IP APIs Detect VPNs
A good IP reputation API cross-references multiple data sources to identify VPN exit nodes:
- BGP/ASN data โ VPN providers register Autonomous System Numbers (ASNs) to announce their IP ranges. The ASN description often reveals the operator (e.g. "Mullvad VPN", "ExpressVPN", "Private Internet Access"). Reputable feeds maintain up-to-date ASN-to-provider mappings.
- Datacenter CIDR ranges โ Most commercial VPNs terminate traffic in cloud or colocation datacenters. IP ranges registered to AWS, Vultr, Hetzner, OVH, and similar providers that are not serving legitimate cloud workloads are strong VPN candidates.
- Shared-exit behaviour โ When tens of thousands of distinct sessions originate from a single /29 subnet over a short window, that subnet is almost certainly a VPN shared-exit pool. Behavioural aggregation across the API's customer base surfaces this.
- Provider-published server lists โ The strongest source is the VPN providers themselves. Mullvad, NordVPN, ProtonVPN, Private Internet Access, Windscribe, and IVPN all publish machine-readable lists of their own relay or server IPs, and Apple publishes iCloud Private Relay's egress ranges as a daily CSV. Predax ingests these directly, alongside curated open datasets of VPN and datacenter ranges.
Two notes on sourcing, because they matter for a trust product. First, Predax deliberately excludes feeds whose licences prohibit commercial use โ several well-known "free" abuse databases fall into that category, and building a paid product on data you're not licensed to resell is not a corner worth cutting. Second, no competitor's API is used as an input. What you get is the combination of provider-published lists, open datasets, and our own observations, folded into a single classification.is_vpn boolean and a classification.risk_score (0โ100) so you don't have to manage multiple feeds yourself.
Making the API Call
curl
curl -s "https://predax.io/api/v1/check/ip" \
-H "X-API-Key: prdx_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"ip": "185.220.101.1"}'A typical response:
{
"ip": "185.220.101.1",
"version": 4,
"classification": {
"risk_score": 92,
"risk_level": "high",
"is_vpn": true,
"is_proxy": false,
"is_tor": true,
"is_datacenter": false,
"flags": ["tor", "vpn"]
},
"network": {
"asn": 4242421337,
"as_name": "Tor exit relay"
},
"location": {
"country_code": "DE",
"country_name": "Germany"
}
}Node.js
async function checkIp(ip) {
const res = await fetch('https://predax.io/api/v1/check/ip', {
method: 'POST',
headers: {
'X-API-Key': process.env.PREDAX_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ ip }),
});
return res.json();
}
// Express middleware example
app.use(async (req, res, next) => {
const visitorIp = req.ip;
const result = await checkIp(visitorIp);
if (result.classification.is_vpn && result.classification.risk_score >= 65) {
return res.status(403).json({ error: 'VPN access is not permitted.' });
}
next();
});Python
import httpx
PREDAX_KEY = "prdx_YOUR_KEY"
def check_ip(ip: str) -> dict:
r = httpx.post(
"https://predax.io/api/v1/check/ip",
headers={"X-API-Key": PREDAX_KEY},
json={"ip": ip},
timeout=2.0,
)
r.raise_for_status()
return r.json()
result = check_ip("185.220.101.1")
classification = result["classification"]
if classification["is_vpn"] and classification["risk_score"] >= 65:
raise PermissionError("VPN access not allowed")How to Act on the Result
The right action depends on your risk tolerance and user base:
| Scenario | Recommended action |
|---|---|
classification.is_vpn: true + risk_score >= 85 | Block outright (Tor/datacenter VPN, very high risk) |
classification.is_vpn: true + risk_score 50โ84 | Flag the session, trigger MFA or CAPTCHA |
classification.is_vpn: true + risk_score 20โ49 | Log and monitor; allow but tag the session |
classification.is_vpn: true + risk_score < 20 | Likely a false positive โ allow and ignore |
Avoid hard-blocking all VPN users unless your use case demands it (e.g. regional licensing). A risk-score threshold of 65 is a reasonable starting point for most login-protection scenarios.
Caveats and False Positives
No VPN detection system is perfect. Residential VPN services (Windscribe, ProtonVPN on residential IPs) are harder to flag because they route traffic through genuine ISP addresses. Corporate VPNs often use office IP ranges that look like normal residential traffic.
Consider letting users whitelist their own IPs if you operate a B2B product โ a developer connecting from their company VPN should not be blocked from their own dashboard. The Predax WordPress and WooCommerce plugins ship an IP allowlist for exactly this reason, and the same pattern is a few lines of code in a custom integration.
Related guides
- How IP risk scoring works โ how the 0โ100
risk_scorewe used in the threshold table is actually computed. - Residential vs datacenter proxies โ why residential VPNs are the hardest to flag and how to handle them.
- Proxy detection API guide โ the broader proxy/VPN/Tor detection picture.
- Blocking Tor users โ when a VPN signal is also a Tor signal, and what to do about it.
- Account takeover prevention โ putting VPN detection into a real login-protection workflow.
- iCloud Private Relay vs Cloudflare WARP โ the two privacy relays that look like VPNs to your detector but shouldn't be blocked like them.
Ready to ship VPN detection in your stack? See pricing โ or drop our WordPress, WooCommerce, or Shopify plugin in for one-click protection.
Frequently Asked Questions
How do you detect if someone is using a VPN?
You look up the address the request arrived on against an IP reputation database and read back what is known about it: whether it belongs to a commercial VPN provider's published range, a hosting or datacenter network, a known open proxy, or a Tor exit. Nothing lets you see a VPN client on the visitor's device - every method is an inference about the address, which is why the answer is a score and a set of flags rather than a yes or no.
How accurate is VPN detection?
Coverage differs sharply by category, because some categories are enumerable and some are not. Tor exits are published by the Tor Project, so detection is near-complete at roughly 99%; commercial VPNs sit around 95% and datacenter ranges around 98%, because both are tied to registered network ownership. Proxies run nearer 90%, and residential proxies are the hardest case of all, because the exit really is an ordinary home connection.
What risk threshold should I use for VPN detection?
It depends entirely on what you do at the threshold, and the distribution makes the choice easier than it looks. Across 93,414 addresses we scored, 75.4% score 0 and only 2.2% score 50 or above, with just 16 addresses landing in the whole 50-64 band - so moving your cutoff by five or ten points changes the outcome for almost nobody. See IP risk scoring explained for the full distribution.
Should I block everyone who shows up on a VPN?
Generally no, and the arithmetic is the reason. In our production data 30.3% of addresses carry a datacenter flag while only about 2% are genuinely risky, so acting on the flag alone turns away roughly a quarter of your traffic to address a two-percent problem. Use the flag to decide how much friction to add, not whether to open the door - the cost of false positives goes through what that trade actually costs.