Skip to content
VPNDetection

Check a list of IPs for VPNs in Python: screening a signup export

Screen a CSV of signup IPs for VPNs and Tor with the vpndetection Python package, one lookup per address, and join each answer back onto its row in pandas.

Published 2 min readLast updated on

On this page
  1. The file
  2. One lookup per address
  3. The whole file in one call, with a paid plan's key

You have a CSV of signups, each with the address it came from, and the question is which of them came through a VPN or Tor. This post screens the whole file with the official vpndetection package on the free plan, one lookup per address, and joins the answers back onto the rows in pandas. We ran every snippet against the live API on November 18, 2026, with Python 3.12, vpndetection 5.17.0 and pandas 3.1.1, and every output below is from those runs.

The file

Our test export has 1,052 rows: 300 Mullvad servers from Mullvad's own server list, 300 Tor exits from the Tor Project's list, 400 home broadband addresses on two cable ISPs, 50 rows that repeat one of those, a private address, and a typo, 203.0.113.300. Its columns are email and signup_ip.

One lookup per address

bash
pip install vpndetection pandas

client.lookup(ip) answers one address. Loop over the file's distinct addresses and join each answer back onto its rows:

python
# screen.py
import pandas as pd
from vpndetection import VPNDetection

client = VPNDetection()
signups = pd.read_csv("signups.csv")

flags = ["is_vpn", "is_tor"]
verdicts = []
for ip in signups["signup_ip"].unique():
    try:
        result = client.lookup(ip)
    except Exception as err:
        print(f"{ip}: {err!r}")
        continue
    verdicts.append({"signup_ip": ip, **{f: result.flagged(f) for f in flags}})

signups = signups.merge(pd.DataFrame(verdicts), on="signup_ip", how="left")
print(signups[flags].sum().to_string())
print(f"needs a second look: {signups[flags].any(axis=1).sum()} of {len(signups)}")
203.0.113.300: VPNDetectionError(kind='bad_request', status=400, message='not a valid IP address')
is_vpn    336
is_tor    308
needs a second look: 631 of 1052

unique() sends each distinct address once, so the 50 repeats cost no request. The private address is answered in the process, with is_bogon set, and never reaches the API. The typo raises its own error, the loop goes on, and its row is empty after the merge. flagged() is True only for a flag that's there and true.

These counts describe our test file, which is mostly VPN and Tor by design.

The whole file in one call, with a paid plan's key

A paid plan's key answers every field, the proxy and hosting flags included, and takes a whole list in one call, lookup_batch. Create one in the console, where a free account can try every field, and set it as VPNDETECTION_API_KEY:

python
# batch.py
import os
import time

import pandas as pd
from vpndetection import VPNDetection

client = VPNDetection(api_key=os.environ["VPNDETECTION_API_KEY"])
signups = pd.read_csv("signups.csv")

start = time.perf_counter()
results = client.lookup_batch(signups["signup_ip"].tolist())
seconds = time.perf_counter() - start
print(f"{len(signups)} rows, {len(results)} addresses, {seconds:.1f} s")

flags = ["is_vpn", "is_tor", "is_resproxy", "is_hosting"]
verdicts = [
    {"signup_ip": ip, **{f: result.flagged(f) for f in flags}}
    for ip, result in results.items()
    if not isinstance(result, Exception)
]
signups = signups.merge(pd.DataFrame(verdicts), on="signup_ip", how="left")
print(signups[flags].sum().to_string())
print(f"needs a second look: {signups[flags].any(axis=1).sum()} of {len(signups)}")
1052 rows, 1002 addresses, 0.5 s
is_vpn         336
is_tor         308
is_resproxy    221
is_hosting     567
needs a second look: 647 of 1052

lookup_batch returns a dict keyed by address, in the order each first appeared, so the 50 repeats collapse into the entries they repeat. The typo carries its own error as its value, and the rest go to the batch endpoint in chunks of up to 1,000 addresses, sent in parallel, so this file took two requests. With no key, every address comes back VPNDetectionError(kind='unauthorized', status=401, message='POST /batch needs an API key on a paid plan'), and with a wrong key, message='invalid API key'. AsyncVPNDetection has the same lookup_batch.

The scripts that rank for this job call the API once per row, with no cache:

python
# naive.py: one request per row, no cache, as most scripts do it
import csv
import os
import time

from vpndetection import VPNDetection

client = VPNDetection(api_key=os.environ["VPNDETECTION_API_KEY"], cache=False)

with open("signups.csv", newline="") as f:
    ips = [row["signup_ip"] for row in csv.DictReader(f)]

start = time.perf_counter()
failed = 0
for ip in ips:
    try:
        client.lookup(ip)
    except Exception:
        failed += 1
seconds = time.perf_counter() - start

print(f"{len(ips)} rows, {failed} failed, {seconds:.1f} s")
1052 rows, 1 failed, 5.6 s

That loop made 1,051 requests where the batch made 2, and took 11 times as long, counted from the HTTP client's log on the same machine and the same list. Without its try, the typo would have stopped it partway through. The two cost the same per address: the API charges each distinct address in a batch as one lookup, so the batch saves the 50 repeats, and the time.

flagged() reads a flag the key's plan doesn't include as False. With no key, is_resproxy is None on every result, which means "not in your plan", not "checked, and no", so it would sum to 0 for that reason alone: read result.is_resproxy is None before you trust a zero.

A file of a few million addresses a day is a few million lookups a day. Past that point, a download of the VPN IP database, refreshed daily and looked up locally, is cheaper, and the same package fetches it with client.database.download on a key that has the db.download scope (pricing).

For the same job without Python, the vpndetection CLI reads a list on stdin. For live traffic, the Django post covers checking each request as it arrives.

Written by

  • Uman Shahzad

    Founder & CEO

    Uman has worked on IP data for over eight years, including as lead engineer at IPinfo. He built systems and practices that IP data companies now use to run at scale and keep their data accurate.

Get new posts by email

Or follow along in a feed reader.

RSS feed

Try it on your own traffic.

The detection these posts describe is one API call away, with SDKs for every major language.

00 · Try it

Free lookups, no sign-up.

Paste it into a terminal. Any address answers its VPN, Tor, relay and anycast flags, where it is, which network announces it and its hostname.

curl "https://api.vpndetection.io/146.70.116.130"
{
"ip": "146.70.116.130",
"is_bogon": false,
"is_vpn": true,
"is_relay": false,
"is_tor": false,
"is_anycast": false,
"relay": {},
"tor": {},
"location": {
"continent": "EU",
"continent_name": "Europe",
"country": "AT",
"country_name": "Austria",
"timezone": "Europe/Vienna",
"currency_code": "EUR",
"currency_name": "Euro",
"currency_symbol": "€",
"flag_emoji": "🇦🇹",
"flag_unicode": "U+1F1E6 U+1F1F9"
},
"asn": {
"asn": 9009,
"name": "M247 Europe SRL",
"domain": "m247global.com",
"prefix": "146.70.116.0/24",
"country": "RO",
"rpki_status": "not_found"
},
"hostname": ""
}
01 · Sign up

Detect VPNs with a free key.

A quota of 50,000 lookups a month with the VPN flag, Tor, relay, country and ASN.
Past it, lookups answer the basics until it resets.
No card and no sales call: the key is issued on signup.
The Data plan answers every field on every lookup.