This guide demonstrates how to detect VPN, proxy, TOR, and bot IP addresses in Rust using the reqwest crate and the Focsec API.

We'll build a type-safe client that checks IP addresses and flags suspicious connections.

1

Add dependencies

Add the required crates to your Cargo.toml:

toml
[dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
2

Define the response types

Create structs to deserialize the API response:

rust
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct IpResponse {
    pub ip: String,
    pub is_vpn: bool,
    pub is_proxy: bool,
    pub is_tor: bool,
    pub is_bot: bool,
    pub is_datacenter: bool,
    pub city: Option<String>,
    pub country: Option<String>,
    pub iso_code: Option<String>,
    pub is_in_european_union: bool,
    pub flag: Option<String>,
    pub autonomous_system_number: Option<u32>,
    pub autonomous_system_organization: Option<String>,
}

impl IpResponse {
    pub fn is_suspicious(&self) -> bool {
        self.is_vpn || self.is_proxy || self.is_tor || self.is_bot || self.is_datacenter
    }
}
3

Check an IP for VPN or proxy

Make an API request to detect VPN and proxy IPs.

Grab your free API key if you haven't already.

rust
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};

const API_KEY: &str = "your-api-key-here";

async fn check_ip(ip: &str) -> Result<IpResponse, reqwest::Error> {
    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        HeaderValue::from_static(API_KEY),
    );

    let client = reqwest::Client::new();
    let response = client
        .get(format!("https://api.focsec.com/v1/ip/{}", ip))
        .headers(headers)
        .send()
        .await?
        .json::<IpResponse>()
        .await?;

    Ok(response)
}

#[tokio::main]
async fn main() {
    match check_ip("82.40.11.200").await {
        Ok(result) => {
            println!("IP: {}", result.ip);
            if result.is_suspicious() {
                println!("VPN/Proxy detected!");
            } else {
                println!("Clean IP");
            }
        }
        Err(e) => eprintln!("Error: {}", e),
    }
}

API Response

Each request returns a structured response with threat indicators and IP metadata:

Response
{
  "ip": "82.40.11.200",
  "is_vpn": false,
  "is_proxy": false,
  "is_bot": false,
  "is_tor": false,
  "is_datacenter": false,
  "city": "London",
  "country": "United Kingdom",
  "iso_code": "gb",
  "is_in_european_union": false,
  "flag": "šŸ‡¬šŸ‡§",
  "autonomous_system_number": 5089,
  "autonomous_system_organization": "Virgin Media Limited"
}

Next steps

Your Rust application can now identify VPN and proxy connections. Explore the API Reference for the full specification.

Ready to get started?

Sign up for a free account and start detecting VPNs, proxies, and bots in your application.

Get your API key »