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 Service 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 purposes. 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 | PX5 | PX6 | PX7 | PX8 | PX9 | PX10 | PX11 |
| 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 = 'https://api.ip2proxy.com/?ip=' . $ipAddress . '&key=demo&package=PX11';
// 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 'You are in local server!
';
echo '';
}
}else{
echo 'IP Address parsing error!';
}
?>
Your IP address <!--?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'])&&isset($proxy['domain'])&&isset($proxy['usageType'])&&isset($proxy['asn'])&&isset($proxy['as'])&&isset($proxy['lastSeen'])&&isset($proxy['threat'])&&isset($proxy['provider'])){ echo 'Response:'."\n". $proxy['response'] . "\n "; echo 'Country Code:'."\n". $proxy['countryCode'] . "\n "; echo 'Country Name:'."\n". $proxy['countryName'] . "\n "; echo 'Region Name:'."\n". $proxy['regionName'] . "\n "; echo 'City Name:'."\n". $proxy['cityName'] . "\n "; echo 'Internet Service Provider:'."\n". $proxy['isp'] . "\n "; echo 'Is Proxy:'."\n". $proxy['isProxy'] . "\n "; echo 'Proxy Type:'."\n". $proxy['proxyType'] . "\n "; echo 'Domain:'."\n". $proxy['domain'] . "\n "; echo 'Usage Type:'."\n". $proxy['usageType'] . "\n "; echo 'ASN:'."\n". $proxy['asn'] . "\n "; echo 'AS:'."\n". $proxy['as'] . "\n "; echo 'Last Seen:'."\n". $proxy['lastSeen'] . "\n "; echo 'Threat:'."\n". $proxy['threat'] . "\n "; echo 'Provider:'."\n". $proxy['provider'] . "\n "; }else{ echo 'IP Address parsing error!'; } ?>
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 = "https://api.ip2proxy.com/?" & "ip=" & IPAddress & "&key=demo&package=PX11"
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 proxytype As String = item("proxyType")
Dim domain As String = item("domain")
Dim usagetype As String = item("usageType")
Dim asn as String = item("asn")
Dim [as] as String = item("as")
Dim lastseen as String = item("lastSeen")
Dim threat as String = item("threat")
Dim provider as String = item("provider")
Dim res As String = item("response")
Response.Write("Welcome Visitors from " + city + "
")
Response.Write("Response: " + res + "
")
Response.Write("Your IP address: " + IPAddress + "
")
Response.Write("Country Code: " + countryc + "
")
Response.Write("Country Name: " + countryn + "
")
Response.Write("Region Name: " + region + "
")
Response.Write("ISP: " + isp + "
")
Response.Write("Is Proxy: " + isproxy + "
")
Response.Write("Proxy Type: " + proxytype + "
")
Response.Write("Domain: " + domain + "
")
Response.Write("Usage Type: " + usagetype + "
")
Response.Write("ASN: " + asn + "
")
Response.Write("AS: " + [as] + "
")
Response.Write("Last Seen: " + lastseen + "
")
Response.Write("Threat: " + threat + "
")
Response.Write("Provider: " + provider + "
")
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 = "https://api.ip2proxy.com/?" + "ip=" + myIP + "&key=demo&package=PX11";
JavaScriptSerializer serializer = new JavaScriptSerializer();
dynamic item = serializer.Deserialize
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("https://api.ip2proxy.com/?" + "ip=" + myIP + "&key=demo&package=PX11");
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 + "
");
System.out.println("Response: " + disp.response + "
");
System.out.println("Your IP address: " + myIP + "
");
System.out.println("Country Code: " + disp.countryCode + "
");
System.out.println("Country Name: " + disp.countryName + "
");
System.out.println("Region Name: " + disp.regionName + "
");
System.out.println("Internet Service Provider: " + disp.isp + "
");
System.out.println("Is Proxy: " + disp.isProxy + "
");
System.out.println("Proxy Type: " + disp.proxyType + "
");
System.out.println("Domain: " + disp.domain + "
");
System.out.println("Usage Type: " + disp.usageType + "
");
System.out.println("ASN: " + disp.asn + "
");
System.out.println("AS: " + disp.as + "
");
System.out.println("Last Seen: " + disp.lastSeen + "
");
System.out.println("Threat: " + disp.threat + "
");
System.out.println("Provider: " + disp.provider + "
");
}
static class Display
{
String cityName;
String countryCode;
String countryName;
String regionName;
String isp;
String isProxy;
String proxyType;
String domain;
String usageType;
String asn;
String as;
String lastSeen;
String threat;
String provider;
String response;
}
}
