Blocking VPN traffic sounds like a single switch. It is not. The useful version of this question is narrower: what do you do when a signup, a checkout or a payout request arrives from an address that is probably not where the person says they are?

This guide covers the part that actually works in production — scoring the connection instead of banning it, picking a threshold you can defend, and wiring it into the three or four places where it changes an outcome. There is working code for Node, PHP, Python and WordPress at the end.

Do not hard-block every VPN

Start here, because it saves most people from an expensive mistake. A meaningful share of ordinary people browse through a VPN all day: remote staff on a corporate tunnel, anyone on a privacy-conscious browser that ships one, travellers, people on mobile networks that route oddly. If you return a 403 to all of them, you will lose real customers and never see the ones you lost.

The traffic that costs you money is rarely "a VPN". It is one of these:

  • One operator running many accounts behind rotating addresses, to claim a bonus or a trial more than once.
  • Card testing against a donation form or a cheap product, from hosting infrastructure.
  • A payout or withdrawal from a country that contradicts everything else on the account.
  • Scripted traffic hitting a form or an offerwall at a speed no human reaches.

All four show up as an anonymising connection, but so does a legitimate customer on a work laptop. The connection is a signal, not a verdict. What separates them is what the connection is combined with, and what you do at each step.

Score the connection, then decide per action

The pattern that holds up is: look up the address, get back a risk score and the reasons behind it, and let each part of your product decide for itself what to do with that number. A page view and a withdrawal should not share a threshold.

A reasonable starting map, which you then tune against your own data:

ActionSuggested responseWhy
Browsing, reading, adding to cartLog onlyNo money moves. Blocking here costs you traffic and buys nothing.
Account creationRequire email plus phone verification above a moderate scoreRaises the cost of farming accounts without turning away one real signup.
Free trial, bonus, referral creditHold the reward for review above a moderate scoreThis is where multi-accounting pays, so this is where friction belongs.
Checkout or depositPass the score to your payment risk rules; step up to 3-D Secure on a high scoreCombines with card signals your processor already has.
Payout, withdrawal, high-value changeManual review on a high score; always review hosting and TorIrreversible. The only place a hard stop is usually right.
Admin and staff loginAlert, never blockYour own team is the group most likely to be on a corporate tunnel.

Note what is missing: a global middleware that rejects every anonymised request before it reaches your app. That design is easy to ship and hard to live with, because the one place it fires hardest is your own support queue.

Read the reasons, not just the number

A score on its own gives you nothing to tune. The categories behind it behave very differently, and they deserve different treatment.

Hosting and datacentre addresses

An address belonging to a cloud or hosting provider is the clearest signal you will get. Ordinary customers do not shop from inside a datacentre. Scripts, scrapers and card-testing runs do, because compute is cheap and disposable. Of everything on this list, this is the category where a firm response at a sensitive step is most defensible.

Commercial VPN exit nodes

Common, often innocent, and the category most likely to generate complaints if you block it. Use it as a reason to ask for verification, not as a reason to refuse service.

Tor exit nodes

A small, well-known and publicly listed set of addresses. Legitimate privacy use exists, but for a payout or a new deposit the combination of Tor plus money moving out is worth a human look.

Residential proxies

The hard one. These route traffic through real consumer connections, so the address looks exactly like a genuine customer's, because it is one — someone whose device is part of a proxy network, often through an app they installed without reading. This is the category most tools miss, and the reason a clean result is not proof of anything.

Mobile and carrier-grade NAT

Worth calling out separately as a false-positive trap. Mobile carriers put thousands of subscribers behind one address, so "many accounts from one IP" is normal on mobile. If you rate-limit on address alone you will punish mobile users hardest, which on most consumer products is the majority.

Where to put the check

Four places, in the order they are worth doing:

  1. Signup. Check the address when the account is created and store the result on the account. This is the single highest-value placement, because every later decision can read it without another lookup.
  2. Reward or trial activation. Check again at the moment value is handed over. Account age tells you a lot here: an address that was clean at signup and anonymised at payout time is a pattern.
  3. Payment and payout. Pass the score into the rules you already have, rather than making a separate block decision.
  4. Form endpoints. Contact forms, comment forms and coupon validation, where automated traffic is cheap to send and expensive to receive.

Two things to get right regardless of placement. First, read the real client address: behind a proxy or CDN the socket address is your own infrastructure, so you need the forwarded header your platform sets, and you need to trust it only from your own edge. Second, never let the lookup block the request — time it out, cache it, and fail open. A detection service being slow should never be the reason a customer cannot sign up.

Implementation

The examples below call 24scan. A request looks like this:

curl "https://api.24scan.com/v1/api?api_key=YOUR_API_KEY&ip=8.8.8.8"

and the part of the response these examples use is data.detections:

{
  "status": "success",
  "data": {
    "detections": {
      "risk_score": 0,
      "confidence": 100,
      "is_proxy": false,
      "is_vpn": true,
      "is_tor": false,
      "is_hosting": false,
      "is_anonymous": false,
      "is_scraper": false,
      "is_compromised": false
    }
  }
}

Each example does the same three things: pull the real client address, look it up with a short timeout, and return a decision the caller can act on.

Node and Express

// Trust the forwarded header only from your own edge.
app.set("trust proxy", 1)

const cache = new Map()
const TTL = 60 * 60 * 1000

async function ipRisk(ip) {
  const hit = cache.get(ip)
  if (hit && hit.until > Date.now()) return hit.value

  const controller = new AbortController()
  const timer = setTimeout(() => controller.abort(), 1500)

  try {
    const url =
      "https://api.24scan.com/v1/api" +
      "?api_key=" + encodeURIComponent(process.env.SCAN_API_KEY) +
      "&ip=" + encodeURIComponent(ip)

    const res = await fetch(url, { signal: controller.signal })
    const body = await res.json()
    const detections = body?.data?.detections ?? null

    cache.set(ip, { value: detections, until: Date.now() + TTL })
    return detections
  } catch {
    // Fail open: a slow lookup must never block a signup.
    return null
  } finally {
    clearTimeout(timer)
  }
}

app.post("/signup", async (req, res, next) => {
  const d = await ipRisk(req.ip)

  req.signupNeedsPhone = Boolean(
    d && (d.is_hosting || d.is_tor || (d.risk_score ?? 0) >= 70)
  )

  next()
})

PHP

<?php
function client_ip(): string {
    // Only read the forwarded header if the request came from your edge.
    $trusted = ['10.0.0.1'];
    $remote  = $_SERVER['REMOTE_ADDR'] ?? '';

    if (in_array($remote, $trusted, true) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        return trim(end($parts));
    }
    return $remote;
}

function ip_risk(string $ip): ?array {
    $cached = apcu_fetch("ipr_$ip");
    if ($cached !== false) return $cached;

    $url = 'https://api.24scan.com/v1/api?api_key=' . urlencode(getenv('SCAN_API_KEY'))
         . '&ip=' . urlencode($ip);

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT_MS     => 1500,
    ]);
    $body = curl_exec($ch);
    curl_close($ch);

    if ($body === false) return null; // fail open

    $detections = json_decode($body, true)['data']['detections'] ?? null;
    apcu_store("ipr_$ip", $detections, 3600);
    return $detections;
}

Python and Django

import os
import requests
from django.core.cache import cache

def ip_risk(ip):
    key = f"ipr:{ip}"
    hit = cache.get(key)
    if hit is not None:
        return hit

    try:
        res = requests.get(
            "https://api.24scan.com/v1/api",
            params={"api_key": os.environ["SCAN_API_KEY"], "ip": ip},
            timeout=1.5,
        )
        detections = res.json().get("data", {}).get("detections")
    except (requests.RequestException, ValueError):
        return None  # fail open

    cache.set(key, detections, 3600)
    return detections


def signup_needs_step_up(request):
    d = ip_risk(request.META["REMOTE_ADDR"])
    if not d:
        return False
    return bool(d.get("is_hosting") or d.get("is_tor")) or d.get("risk_score", 0) >= 70

WordPress

On WordPress the thing worth protecting is usually registration, comments, WooCommerce checkout and the login form — not every page view. Checking on every request burns your query allowance on visitors who were never going to cost you anything.

add_filter('registration_errors', function ($errors) {
    $risk = ip_risk(client_ip());

    if ($risk && (!empty($risk['is_hosting']) || ($risk['risk_score'] ?? 0) >= 80)) {
        $errors->add(
            'ip_risk',
            __('We could not verify your connection. Please try again without a VPN or proxy, or contact support.')
        );
    }

    return $errors;
}, 10, 1);

Note the message. It tells the person what to change and gives them a way through. "Access denied" generates support tickets; this does not.

Picking a threshold you can defend

Do not pick a number from a blog post, including this one. Run the check in log-only mode for a week or two, store the score against every signup, then look at what it would have done:

  • How many of your known-good customers would have been stopped? That is your false-positive cost, in names you recognise.
  • How many accounts you later banned, refunded or charged back were above the line? That is the benefit.
  • Where do those two curves cross for your business?

The answer differs enormously by model. A rewards app paying cash for offer completions can justify a far lower threshold than a B2B SaaS trial, because the downside of a wrong block is a lost lead in one case and a few cents in the other.

Then keep watching it. Thresholds rot: proxy networks change, your traffic mix changes, and a number that was right in January quietly starts costing you signups by June.

What this does not solve

Worth being plain about, because the gap is where most of the remaining loss lives.

Address intelligence tells you about a connection. It does not tell you about a person. Someone determined to run accounts at scale will buy residential proxy access and present addresses that look indistinguishable from your real customers, because they belong to real customers' connections. A clean result means "nothing known against this address", not "this is a genuine new user".

So the address check earns its place as a cheap first filter that removes the high-volume, low-effort attempts, and as one input among several for the rest. The signals that catch the determined operator are different in kind: device and browser consistency, how the account behaves in its first minutes, whether the payment instrument has been seen before, and velocity across accounts rather than across addresses.

Build the cheap layer first. It is one HTTP call, it stops the bulk of the automated noise, and it gives you the data you need to know whether the expensive layers are worth it.

Common questions

Will blocking VPN traffic hurt my SEO?

Search crawlers do not arrive through consumer VPNs, so a well-scoped rule does not touch them. A badly scoped one can: if you block by hosting category on every page view, you risk blocking crawlers, uptime monitors and preview bots, all of which legitimately run in datacentres. Verify crawlers properly and keep the check off your public content pages.

An IP address is personal data in the EU, so you need a lawful basis and you should say what you are doing in your privacy notice. Fraud prevention is commonly handled as a legitimate interest, which is why most payment and risk tooling operates on that basis — but the assessment is yours to make and worth putting in writing. If you process EU personal data you will also want a data processing agreement with whichever provider you use.

Can someone tell I am checking?

Not from a server-side lookup. The check happens between your backend and the detection API; nothing is added to the page and nothing runs in the visitor's browser.

How many lookups will I need?

Far fewer than your pageview count, if you place the check at the four points above rather than globally, and cache per address. Most sites that check at signup, reward, payment and form submission use a small fraction of what they expected.