code examples / proxycheck.io

Below you'll find code examples written by both us and 3rd party developers which enable you to integrate the proxycheck.io API with your software and services. If you've written a publicly available implementation of the proxycheck.io API such as a code example, function, class or plugin please contact us and we'll be happy to include it below. You can find ready to use plugins on our plugins page.


PHP Code

If you don't want to use the Composer library at all and instead would prefer a basic function we have provided that here on our GitHub page.

Below is the install command for our composer library. You can find the instructions for using the library here on GitHub.

composer require proxycheck/proxycheck-php

Below is an example calling the library and retrieving the result of the query into an array.

// Get your visitors IP Address
// If you're using CloudFlare change $_SERVER["REMOTE_ADDR"] to $_SERVER["HTTP_CF_CONNECTING_IP"]
$ip = $_SERVER["REMOTE_ADDR"];

// Input your options for this query including your optional API Key and query flags.
$proxycheck_options = array(
  'API_KEY' => '######-######-######-######', // Your API Key.
  'ASN_DATA' => 1, // Enable ASN data response.
  'DAY_RESTRICTOR' => 7, // Restrict checking to proxies seen in the past # of days.
  'VPN_DETECTION' => 1, // Check for both VPN's and Proxies instead of just Proxies.
  'INF_ENGINE' => 1, // Enable or disable the real-time inference engine.
  'TLS_SECURITY' => 0, // Enable or disable transport security (TLS).
  'QUERY_TAGGING' => 1, // Enable or disable query tagging.
  'CUSTOM_TAG' => '', // Specify a custom query tag instead of the default (Domain+Page).
  'BLOCKED_COUNTRIES' => array('Wakanda', 'Mordor') // Specify an array of countries to be blocked.
);
  
$result_array = \proxycheck\proxycheck::check($ip, $proxycheck_options);

The above library supports all of our API features which includes all of our query flags and custom query tagging. We've also added library-side country blocking so you can use the API as a country blocking system aswell. You can view its dedicated page which includes full instructions here at packagist.org

If you don't want to use composer you can instead install the library yourself manually from our github page here where you will also find the instructions for using the library.

curl

Accessing our API through curl either by commandline or within a language such as PHP is very easy. All our API responses are in JSON so you will need to parse those responses but you can call our API from curl with the command below.

$ curl "http://proxycheck.io/v2/8.8.8.8"

When you do so you should receive a response like so:

{
    "8.8.8.8": {
        "proxy": "no",
        "provider": "GOOGLE - Google LLC, US"
    }
}
C# Code

Developer hollow87 has made available a nuget package for proxycheck.io at nuget.org available here thanks hollow87! - We've included some install commands for popular clients below for your convenience.

Install-Package ProxyCheck -Version 1.0.0
dotnet add package ProxyCheck --version 1.0.0
paket add ProxyCheck --version 1.0.0

You can download a C# console app / assembly from GitHub here made by developer hollow87. We thank him for this valuable contribution. For your convenience we have included the code below.

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ProxyCheck
{
    public class ProxyCheck
    {
        public class ProxyCheckResposne
        {
            [JsonProperty(PropertyName = "node")]
            public string Node { get; internal set; }

            [JsonProperty(PropertyName = "asn")]
            public string ASN { get; internal set; }

            [JsonProperty(PropertyName = "provider")]
            public string Provider { get; internal set; }

            [JsonProperty(PropertyName = "country")]
            public string Country { get; internal set; }

            [JsonProperty(PropertyName = "ip")]
            public string IP { get; internal set; }

            public IPAddress IPAddress => IPAddress.Parse(IP);

            [JsonProperty(PropertyName = "proxy")]
            public string Proxy { get; internal set; }

            public bool IsProxy => Proxy.ToLower() == "yes";

            [JsonProperty(PropertyName = "type")]
            public string Type { get; internal set; }

            [JsonProperty(PropertyName = "query time")]
            public string QueryTime { get; internal set; }

            [JsonProperty(PropertyName = "error")]
            public string Error { get; internal set; }
        }

        private const string PROXYCHECKURL = "proxycheck.io/v1";

        /// 
        /// The API key to use with the query
        /// 
        public string ApiKey { get; set; } = "";

        /// 
        /// Including checking for VPN
        /// 
        public bool IncludeVPN { get; set; }

        /// 
        /// Use HTTPS when checking IP address (slower)
        /// 
        public bool UseTLS { get; set; }

        /// 
        /// Enables viewing the ASN of the network the IP address belongs to
        /// 
        public bool IncludeASN { get; set; }

        /// 
        /// Includes the answering node in the reply
        /// 
        public bool IncludeNode { get; set; }

        /// 
        /// Includes the time it took for query
        /// 
        public bool IncludeTime { get; set; }

        public async Task IsProxyAsync(IPAddress ipAddress, string tag = "")
        {
            try
            {
                var response = await QueryAsync(ipAddress, tag);

                if (!string.IsNullOrWhiteSpace(response.Error))
                    throw new Exception(response.Error);

                return response.IsProxy;
            }
            catch(Exception e)
            {
                // Just rethrowing the exception
                throw;
            }
        }

        public async Task QueryAsync(IPAddress ipAddress, string tag = "")
        {
            var url = new StringBuilder()
                .Append($"{(UseTLS ? "https://" : "http://")}{PROXYCHECKURL}/{ipAddress}")
                .Append(!string.IsNullOrWhiteSpace(ApiKey) ? $"&key={ApiKey}" : "")
                .Append($"{(IncludeVPN ? "&vpn=1" : "")}")
                .Append($"{(IncludeASN ? "&asn=1" : "")}")
                .Append($"{(IncludeNode ? "&node=1" : "")}")
                .Append($"{(IncludeTime ? "&time=1" : "")}");

            using (var client = new HttpClient())
            {
                FormUrlEncodedContent content = null;
                
                if (!string.IsNullOrWhiteSpace(tag))
                {
                    content = new FormUrlEncodedContent(new Dictionary
                    {
                        {"tag", tag}
                    });
                }

                try
                {
                    HttpResponseMessage response = null;
                    if (content != null)
                        response = await client.PostAsync(url.ToString(), content);
                    else
                        response = await client.GetAsync(url.ToString());

                    string json = await response.Content.ReadAsStringAsync();

                    ProxyCheckResposne result = JsonConvert.DeserializeObject(json);

                    return result;
                }
                catch(Exception e)
                {
                    // Should do something here just rethrowing
                    throw;
                }
            }

        }
    }
}

Java

DefianceCoding has created a free Java API and example classes for creating Java plugins and applets that integrates the proxycheck.io v2 API. You can view the latest version of PCDetectionAPI on GitHub here

  • Utilises the latest v2 proxycheck.io API
  • Supports our status response codes
  • Supports all our query flags

If you need support or have found a bug you can email DefianceCoding at [email protected]ail.com or on Discord here

Node.js

Accessing the API with Node.js is very easy as shown by the code snippet below.

const request = require('request')

request('http://proxycheck.io/v2/8.8.8.8', function(error, res, body) {
  console.log(JSON.parse(body))
})

When you do so you should receive a response like so:

{
    "8.8.8.8": {
        "proxy": "no",
        "provider": "GOOGLE - Google LLC, US"
    }
}
Python

Accessing the API with Python is very easy as shown by the code snippet below.

requests.get('http://proxycheck.io/v2/8.8.8.8')

When you do so you should receive a JSON response that you will need to parse like so:

{
    "8.8.8.8": {
        "proxy": "no",
        "provider": "GOOGLE - Google LLC, US"
    }
}
Ruby on Rails

Jonathan has been kind enough to create a gem for utilising the proxycheck.io API and you can find it on the rubygems.org website here thanks jonathan! - We've included the gem install command below for your convenience.

gem install proxycheck

Below we've included a simple way to query the API with Ruby.

require 'json'
require 'open-uri'

JSON.parse(open('http://proxycheck.io/v2/8.8.8.8').read)

When you do so you should receive a JSON response like so:

{
    "8.8.8.8": {
        "proxy": "no",
        "provider": "GOOGLE - Google LLC, US"
    }
}

Back
Last Update: 24th of July 2018
24th of July 2018
Added a new Java tab which includes a new Java API from DefianceCoding.
1st of July 2018
Moved around the position of our Basic PHP Function so it's more visible for users who just want to use that instead of our Composer library.
9th of June 2018
Added composer install instructions to the PHP example code tab. Removed our basic PHP example and replaced it with a link to our PHP function.
2nd of January 2018
Most example code was updated to use the new v2 API and the CSS styling was updated.
10th of November 2017
New examples were added for curl, Node.js, Python and Ruby, layouts were also updated.
13th of September 2017
The page apperance was updated with a new tab view for the different examples, this is getting ready for a wider selection of examples coming soon. A C# example was also added.
26th of June 2017
Three new minecraft plugins were added to the page.
25th of May 2017
The PHP Example was updated to include our new query tagging feature.
7th of April 2017
A better PHP example utilising functions and curl on GitHub was linked to from this page.
1st of April 2017
Information about a 3rd party Minecraft plugin which uses our API was added to the page.