Display Visitor’s Proxy Using IP2Proxy Web Service

In this tutorial, we use the IP2Proxy™ Web Service to detect proxy details from the visitor’s IP address. Instead of loading the full database, you can also lookup IP address via our hosted web service.

IP2Proxy™ Web API uses a single web interface to perform the lookup logic. The protocol used is HTTP GET. You can test this API as easy as using a web browser.

api.ip2proxy.com/?ip=<ip_address>&key=<your_api_key>&package=<package>&format=<format>

 

PARAMETERS
Name Description
key (required) API key. Please use “demo” for evaluation.
ip (optional) IP address (IPv4) for lookup purpose. If not present, the server IP address will be used for the lookup.
package (optional) If not present, the web service will assume the PX1 package query. Valid value: PX1 | PX2 | PX3 | PX4
format (optional) If not present, json format will be returned as the search result. Valid value: json | xml

Below are the sample codes written in PHP to query and display user’s proxy information.

<?php
 $host= gethostname();
 $ipAddress = gethostbyname($host);
 $urlTemplate = 'http://api.ip2proxy.com/?ip=' . $ipAddress .  '&key=demo&package=PX4';
 
 // replace the "%s" with real IP address
 $urlToCall = sprintf( $urlTemplate, $ipAddress);
 
 $rawJson = file_get_contents( $urlToCall );
 
 $proxy = json_decode( $rawJson, true );
 
 if(isset($proxy['cityName'])){
 
    if($proxy['cityName']=="-"){
        echo '<center>You are in local server!</center><br>';
        echo '<script language="javascript">';
        echo 'alert("You are in local server!")';
        echo '</script>';
    }
}else{
    echo 'IP Address parsing error!';
}
?>
<html>
<head>
<title>IP2Proxy Web Service</title>
</head>
<body>
<div>
<center><a href="https://www.ip2location.com/ip2proxy-web-service">IP2Proxy Web Service</a></center><br>
 
</div>
<div>
<center>Your IP address <?php echo $ipAddress; ?></center>
      <center>
      <?php
      if(isset($proxy['response'])&&isset($proxy['countryCode'])&&isset($proxy['countryName'])&&isset($proxy['regionName'])&&isset($proxy['cityName'])&&isset($proxy['isp'])&&isset($proxy['isProxy'])&&isset($proxy['proxyType'])){
        echo '<br>Response:'."\n". $proxy['response'] . "\n<br>";
        echo 'Country Code:'."\n". $proxy['countryCode'] . "\n<br>";
        echo 'Country Name:'."\n". $proxy['countryName'] . "\n<br>";
        echo 'Region Name:'."\n". $proxy['regionName'] . "\n<br>";
        echo 'City Name:'."\n". $proxy['cityName'] . "\n<br>";
        echo 'Internet Service Provider:'."\n". $proxy['isp'] . "\n<br>";
        echo 'Is Proxy:'."\n". $proxy['isProxy'] . "\n<br>";
        echo 'Proxy Type:'."\n". $proxy['proxyType'] . "\n<br>";
      }else{
          echo 'IP Address parsing error!';
      }
      ?>
      </center>
</div>
</body>
</html>

 

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    WebAPI()
End Sub
 
Private Sub WebAPI()
    Dim strQuery As String
    Dim IPAddress As String = HttpContext.Current.Request.UserHostAddress
    Dim Key As String = "demo"
    Dim serializer As New JavaScriptSerializer()
    Dim HttpWReq As HttpWebRequest
    Dim HttpWResp As Net.HttpWebResponse
 
    strQuery = "http://api.ip2proxy.com/?" & "ip=" & IPAddress & "&key=demo&package=PX4"
    HttpWReq = WebRequest.Create(strQuery)
    HttpWReq.Method = "GET"
    HttpWResp = HttpWReq.GetResponse()
 
    Dim reader As System.IO.StreamReader = New IO.StreamReader(HttpWResp.GetResponseStream())
    Dim content As String = reader.ReadToEnd
    Dim item As Object = serializer.Deserialize(Of Object)(content)
    Dim city As String = item("cityName")
    Dim countryc As String = item("countryCode")
    Dim countryn As String = item("countryName")
    Dim region As String = item("regionName")
    Dim isp As String = item("isp")
    Dim isproxy As String = item("isProxy")
    Dim protype As String = item("proxyType")
    Dim res As String = item("response")
 
    Response.Write("Welcome Visitors from " + city + "<br />")
    Response.Write("Response: " + res + "<br />")
    Response.Write("Your IP address: " + IPAddress + "<br />")
    Response.Write("Country Code: " + countryc + "<br />")
    Response.Write("Country Name: " + countryn + "<br />")
    Response.Write("Region Name: " + region + "<br />")
    Response.Write("Latitude: " + isp + "<br />")
    Response.Write("Longitude: " + isproxy + "<br />")
    Response.Write("Time Zone: " + protype)
End Sub
Sub Main()
    WebAPI()
End Sub

 

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        WebAPI();
    }
 
    private void WebAPI()
    {
        string myIP = HttpContext.Current.Request.UserHostAddress;
        string strQuery;
        string key = "demo";
        HttpWebRequest HttpWReq;
        HttpWebResponse HttpWResp;
        strQuery = "http://api.ip2proxy.com/?" + "ip=" + myIP + "&key=demo&package=PX4";
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        dynamic item = serializer.Deserialize<object>(content);
        HttpWReq = (HttpWebRequest)WebRequest.Create(strQuery);
        HttpWReq.Method = "GET";
        HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
        System.IO.StreamReader reader = new System.IO.StreamReader(HttpWResp.GetResponseStream());
        string content = reader.ReadToEnd();
 
        string city = item["cityName"];
        string countryc = item["countryCode"];
        string countryn = item["countryName"];
        string region = item["regionName"];
        string isp = item["isp"];
        string isproxy = item["isProxy"];
        string protype = item["proxyType"];
        string res = item["response"];
 
        //displaying the result
        Response.Write("Welcome Visitors from " + city + "<br />");
        Response.Write("Response: " + res + "<br />");
        Response.Write("Your IP address: " + myIP + "<br />");
        Response.Write("Country Code: " + countryc + "<br />");
        Response.Write("Country Name: " + countryn + "<br />");
        Response.Write("Region Name: " + region + "<br />");
        Response.Write("Internet Service Provider: " + isp + "<br />");
        Response.Write("Is Proxy: " + isproxy + "<br />");
        Response.Write("Proxy Type: " + protype + "<br />");
    }
}

 

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URL;
import com.google.gson.Gson;
 
public class System
{
    public static void main(String[] args) throws Exception
    {
        Gson gson = new Gson();
        String myIP = Request.UserHostAddress;
        String json = readURL("http://api.ip2proxy.com/?" + "ip=" + myIP + "&key=demo&package=PX4");
        System.out.println(json);
 
        Map< String, Object > decoded = gson.fromJson(
            json,
            new TypeToken< Map< String, Object>>() {}.getType());
        System.out.println( decoded );
 
        //displaying the result
        Display disp = gson.fromJson(json, Display.class);
        System.out.println("Welcome Visitors from " + disp.cityName + "<br />");
        System.out.println("Response: " + disp.response + "<br />");
        System.out.println("Your IP address: " + myIP + "<br />");
        System.out.println("Country Code: " + disp.countryCode + "<br />");
        System.out.println("Country Name: " + disp.countryName + "<br />");
        System.out.println("Region Name: " + disp.regionName + "<br />");
        System.out.println("Internet Service Provider: " + disp.isp + "<br />");
        System.out.println("Is Proxy: " + disp.isProxy + "<br />");
        System.out.println("Proxy Type: " + disp.proxyType + "<br />");
    }
    static class Display
    {
        String cityName;
        String countryCode;
        String countryName;
        String regionName;
        String isp;
        String isProxy;
        String proxyType;
        String response;
    }
}

 

 

Was this article helpful?

Related Articles