Checking a HTTP proxy status and type


Introduction

When you want to use a proxy you need this informations about it. And you can check this in a simple way by made a request to a page that is already doing this: www.pan-internet.com (or many others). A web page can tell you if your proxy is safety by analyzing your request techincal details information; every web developer can do this, this information are in request object.

So...to simplify this .... how can you check if a proxy is working? There is a simple way: you made an request to a dedicated page that is doing this - see the server-side section - a place where i write, in XML format the proxy variables that can referr to a proxy request and that can tell you if that proxy is anonymus/transparent.

What means that a proxy is transparent? 1st, is good to know that in the moment when you made a request to a server your IP or your proxy IP will be displayed on the reqeuested page header in a variable called REMOTE_ADDR. When you made a proxy request that and your proxy is transparent your IP address will be displayed in some dedicated fiels: HTTP_X_FORWARDED_FOR, HTTP_VIA or HTTP_PROXY_CONNECTION; with other words your request will be transparent for the requested server. An anonymus server will send to the requested age only it's IP, and nothing about your data.

In this way I made a simple application to see if a proxy is working or not. It is a simple desktop application and you can see the code for this application, so it doesn't have nothing that can help me to use your resources. So you can trust it.

Server-side code

This code generates an XML response that contains all proxy related request fields. With other words, the obects that you can see in this aticle intro: REMOTE_ADDR, HTTP_X_FORWARDED_FOR, HTTP_VIA and HTTP_PROXY_CONNECTION.

 <%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/xml";
System.Text.StringBuilder db = new System.Text.StringBuilder();
db.Append("");
db.Append(context.Request["REMOTE_ADDR"]);
db.Append("
");
db.Append(context.Request["HTTP_X_FORWARDED_FOR"]);
db.Append("
");
db.Append(context.Request["HTTP_VIA"]);
db.Append("
");
db.Append(context.Request["HTTP_PROXY_CONNECTION"]);
db.Append("
");
context.Response.Write(db.ToString());

}

public bool IsReusable {
get {
return false;
}
}
}

You can see this code result here.

Desktop application code

Here is more simple: I made an request to my previsous page and I parse the response.


 string getWebResponse(string proxyHost, int port)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URLVerifyer);//Prepare the request
if (proxyHost.Length > 3)
if (proxyHost.Contains("."))
{ //if we have an valid proxy then add it to our request, else made a request without a proxy
request.Proxy = new WebProxy(proxyHost, port);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
XmlSerializer serializer = new XmlSerializer(typeof(ProxyResult));
proxyResult = (ProxyResult)serializer.Deserialize(s);//parse the response into an internal object; this is why I use XML on server side
string responseStr = proxyResult.ToString();

s.Close();
response.Close();
request.Abort();
return responseStr;
}
catch (Exception exc)
{
return exc.Message;
}
}

To get all the code, you can Download proxy_status.zip - 70.41 KB - this project.

Why

First time when it was necesary to work with proxys was on my 1st job where I have to create some http bots, some crawlers that extracts data from some big sites. There I made this with a lot web sites. Now I made a site where I try to solve this problem in a general way, for everybody, http://www.pan-internet.com/proxy.aspx, from there you can get free proxy servers and a lot of other stuffs.

Up Next
    Ebook Download
    View all
    Learn
    View all