ipasis
Blog/Security Engineering

Programmatic Detection of VPN and Proxy Traffic via IP Intelligence

December 14, 20258 min read

The Anonymity Vector in Application Security

For enterprise applications, the distinction between legitimate user privacy and malicious anonymity is critical. While VPNs serve valid privacy needs, they—along with residential proxies, Tor nodes, and hosting provider IPs—are the primary vectors for credential stuffing, credit card fraud, and geo-restriction bypass.

Implementing static blocklists is no longer sufficient due to the high churn rate of proxy pools. The solution lies in real-time IP intelligence: querying an API that aggregates signal data from honeypots, BGP routing tables, and traffic analysis to determine the probability of an IP being a masking agent.

The Mechanics of IP Intelligence

IP reputation APIs analyze network layer data to classify traffic. Key indicators include:

  • ASN Classification: Identifying if traffic originates from an ISP (Residential) or a Hosting Provider (Datacenter).
  • Open Port Scanning: Detecting open proxies (SOCKS4/5, HTTP).
  • Behavioral History: analyzing recent abuse reports associated with the subnet.

Implementation Guide

Below are implementation patterns for integrating the IPASIS API into your authentication or firewall middleware.

Python Implementation

This script demonstrates a synchronous check suitable for blocking logic within a Django or Flask view.

import requests
import json

def analyze_ip_risk(ip_address, api_key):
    endpoint = "https://api.ipasis.com/v1/reputation"
    params = {
        "ip": ip_address,
        "apikey": api_key
    }

    try:
        response = requests.get(endpoint, params=params, timeout=2.0)
        response.raise_for_status()
        data = response.json()

        # Risk Evaluation Logic
        security = data.get('security', {})
        
        if security.get('is_vpn') or security.get('is_proxy'):
            return {
                "status": "BLOCK",
                "reason": "Anonymizer Detected",
                "type": "VPN/Proxy"
            }
            
        if security.get('is_tor'):
             return {
                "status": "BLOCK",
                "reason": "Tor Exit Node",
                "type": "Tor"
            }
            
        return {"status": "ALLOW", "reason": "Clean IP"}

    except requests.exceptions.RequestException as e:
        # Fallback strategy: Fail open or log error
        print(f"API Error: {e}")
        return {"status": "ALLOW", "reason": "API Failover"}

Node.js Implementation

For high-throughput environments (Express/Fastify), use an asynchronous pattern to minimize event loop blocking.

const axios = require('axios');

async function checkIpReputation(ipAddress, apiKey) {
  const url = `https://api.ipasis.com/v1/reputation?ip=${ipAddress}&apikey=${apiKey}`;

  try {
    const response = await axios.get(url, { timeout: 2000 });
    const { security } = response.data;

    // Strict checking for high-risk endpoints (e.g., Payment Gateways)
    const isHighRisk = security.is_vpn || 
                       security.is_proxy || 
                       security.is_tor;

    if (isHighRisk) {
      return {
        allow: false,
        risk_score: security.risk_score,
        threat: security.threat_type
      };
    }

    return { allow: true };

  } catch (error) {
    console.error('IPASIS Lookup Failed:', error.message);
    // Default to allow to prevent user friction during outages
    return { allow: true };
  }
}

Integration Strategies

Do not query the API on every static asset request. Instead, strategically place checks at critical friction points:

  1. Registration & Login: Prevent sock-puppet account creation and credential stuffing.
  2. Checkout: Reduce chargeback risks by flagging mismatched billing location and IP location.
  3. API Rate Limiting: Apply stricter rate limits to traffic identified as datacenter/hosting IPs compared to residential ISPs.

Handling False Positives

Binary blocking (Allow/Deny) is effective for Tor and known abuse nodes. However, for generic VPNs, consider a "Challenge" response. If is_vpn is true, trigger 2FA or a CAPTCHA rather than a hard 403 Forbidden. This balances security with user experience for legitimate privacy-conscious users.

FAQ

Q: How does this differ from local GeoIP databases? local databases provide location data but lack real-time context regarding the nature of the IP (e.g., if it was recently compromised and turned into a botnet node). APIs provide live security telemetry.

Q: What is the latency impact? IPASIS is engineered for sub-100ms response times. However, proper timeout handling (fail-open) is required in your code to prevent cascading failures.

Q: Can this detect residential proxies? Yes. While harder to detect than datacenter proxies, advanced reputation APIs analyze connection patterns and device fingerprinting correlations to flag residential IPs being used as exit nodes.

Secure Your Infrastructure with IPASIS

Stop relying on outdated blocklists. Integrate enterprise-grade IP intelligence into your stack today.

Get your free API Key at IPASIS and start filtering malicious traffic immediately.

Start detecting VPNs and Bots today.

Identify anonymized traffic instantly with IPASIS.

Get API Key