In this guide, you'll learn how to identify VPN, proxy, TOR, and bot traffic in your Go application using the Focsec API and Go's standard library.

We'll cover everything from making your first API request to building a reusable detection function.

1

Define the response struct

Create a struct to parse the API response:

go
package main

type IPResponse struct {
    IP                           string `json:"ip"`
    IsVPN                        bool   `json:"is_vpn"`
    IsProxy                      bool   `json:"is_proxy"`
    IsTor                        bool   `json:"is_tor"`
    IsBot                        bool   `json:"is_bot"`
    IsDatacenter                 bool   `json:"is_datacenter"`
    City                         string `json:"city"`
    Country                      string `json:"country"`
    ISOCode                      string `json:"iso_code"`
    IsInEuropeanUnion            bool   `json:"is_in_european_union"`
    Flag                         string `json:"flag"`
    AutonomousSystemNumber       int    `json:"autonomous_system_number"`
    AutonomousSystemOrganization string `json:"autonomous_system_organization"`
}
2

Check an IP for VPN or proxy

Make an API request to detect VPN and proxy IPs.

Need an API key? Create a free account to get started.

go
package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

const apiKey = "your-api-key-here"

func checkIP(ip string) (*IPResponse, error) {
    url := fmt.Sprintf("https://api.focsec.com/v1/ip/%s", ip)

    req, err := http.NewRequest("GET", url, nil)
    if err != nil {
        return nil, err
    }

    req.Header.Set("Authorization", apiKey)

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    var result IPResponse
    if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
        return nil, err
    }

    return &result, nil
}

func main() {
    result, err := checkIP("82.40.11.200")
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }

    fmt.Printf("IP: %s\n", result.IP)
    fmt.Printf("VPN: %v, Proxy: %v, TOR: %v\n",
        result.IsVPN, result.IsProxy, result.IsTor)
}

API Response

You'll receive a JSON response with security flags and location information:

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"
}
3

Detect suspicious IPs

Add a method to check if an IP is using any anonymization:

go
func (r *IPResponse) IsSuspicious() bool {
    return r.IsVPN || r.IsProxy || r.IsTor || r.IsBot || r.IsDatacenter
}

func main() {
    result, err := checkIP("82.40.11.200")
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }

    if result.IsSuspicious() {
        fmt.Printf("VPN/Proxy detected: %s\n", result.IP)
    } else {
        fmt.Printf("Clean IP: %s\n", result.IP)
    }
}

Next steps

Your Go application is now equipped to detect VPN and proxy traffic. Visit the API Reference for the complete list of response fields.

Ready to get started?

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

Get your API key »