Link to home
Start Free TrialLog in
Avatar of Ventura_v
Ventura_v

asked on

Check if a IP is a proxy

Hello Experts,

How can I do to check if some IP is a public proxy?? I thought about using IdTCPClient and try to connect at all ports, but then i realised that it wouldn't be enought... If it connects, it may be just an IP with a port open... Do I have to send some data to the connected IP to check if its a proxy?? If yes, what kind of data??

Thanks in advance
Avatar of ubsoc
ubsoc
Flag of United States of America image

On way to check is if you have the IP and port, enter that into your internet explorer under Tools/Internet Options/Connections/Lan Settings.
If you can browse the internet it is good. If you can't well, then it is not.

This would be difficult if you don't know the port to use because the port setting of a proxy server is almost never port 80 in my experience, but you never know.
Avatar of ThievingSix
I suppose you can connect through the proxy and try to gather a set data that doesn't change such as the word "Google" on google.com
Avatar of Ventura_v
Ventura_v

ASKER

Hmm, but if i'm testing all ports in an IP, testing it with a webbrowser would be really slow... I hear that if that IP is a proxy and you connect to it in the right port, you send someting like "GET www.google.com http/1.1" ...
here is a proxy checker code I wrote ages ago (I am little shocked at how I could code like that. the entire application is a totall mess. funny it works.)
sure, you can write your won from cratch, sending the needed (proxy) information then reading back, etc. but tidsocksinfo already does all this for you.
basically, if you can connect to a server/host through a proxy, it means it is a proxy. and that is because if it's a proxy it replies to a specific message in a specific way ;) you don't neet go send GET and otehr stuff.
well, you need to do that if you want to know what kind of proxy it is. since some procies only proxy email, others only http, others only whatever there is.
and that's just because the owners choosed not to proxy different protocols. so in order to see if you can proxy http for example, sure, you will need to tets for http. but in this case, I say that you use TIdHttp and do a HEAD (not GET) for google.com if it returns correctly (response code 200) then it proxies http, otherwise, it doesn't.
procedure TChecker.checkProxy(p:string);// p(roxy) like ip:port
var c:TIdTCPClient; 
    i:integer;
    ioh:TIdIOHandlerSocket; 
    s:TIdSocksInfo;
begin
  s:=TIdSocksInfo.Create(owner);
  ioh:=TIdIOHandlerSocket.Create(owner);
  c:=TIdTCPClient.Create(owner);;
 
  c.IOHandler:=ioh;
  ioh.SocksInfo:=s;
  // here comes the timeout
  c.ReadTimeout:=timeOut div 3;// we will make 3 connections, so the timeout is the overall time out  
  c.Host:=server;// example: microsoft.com 
  c.Port:=port;// example: 25
  i:=pos(':',p);
  s.Host:=copy(p,1,i-1);
  s.Port:=strtoint(copy(p,i+1,length(p)));
  s.Authentication:=saNoAuthentication;
  info.good:=false;// info is just a data holder object sahred by this thread and a thread-freeze-checker thread
  info.version:=svNoSocks;
  try
    s.Version:=svSocks5;
    c.Connect;
    if not info.killed then// another thread was checking if this one is freezing or not (per the tiomeout, and if so, it was forcibly disconnecting and marking it as killed)
    begin
      info.good:=true;// found it
      info.version:=svSocks5;
    end;
    c.Disconnect;
  except
    if (not info.good) and (not info.killed) then// try another version
    try
      s.Version:=svSocks4A;
      c.Connect;
      if not info.killed then// same blabla
      begin
        info.good:=true;
        info.version:=svSocks4A;
      end;
      c.Disconnect;
    except
      if (not info.good) and (not info.killed) then// and again
      try
        s.Version:=svSocks4;
        c.Connect;
        if not info.killed then
        begin
          info.good:=true;
          info.version:=svSocks4;
        end;
        c.Disconnect;
      except
      end;
    end;
  end;
end;

Open in new window

"so in order to see if you can proxy http for example, sure, you will need to tets for http. but in this case, I say that you use TIdHttp and do a HEAD (not GET) for google.com if it returns correctly (response code 200) then it proxies http, otherwise, it doesn't."

That's exactly what i want, to test for http proxy... This response is handled by which event?? OnWork?? Or just if IdHTTP.Head(SITE) = 200 then something??
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm I got some error in the line:
 Result:=idhttp1.ResponseCode=200;
The error is the following: "Project Project1.exe raised exception class EIdHTTPProtocolException with message 'HTTP /1.0 302 Moved Temporarily'"

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls;
 
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    IdHTTP1: TIdHTTP;
    function IsProxy(IP: string): boolean;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
function TForm1.IsProxy(IP: string): boolean;
begin
Result:=false;
try
  IdHTTP1.ProxyParams.ProxyServer:=copy(edit1.Text,1,pos(':',edit1.Text)-1);
  IdHTTP1.ProxyParams.ProxyPort:=strtoint(copy(edit1.Text,pos(':',edit1.Text)+1,length(edit1.Text)));
  idhttp1.head('http://www.google.com');
  Result:=idhttp1.ResponseCode=200;
except
end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsProxy(edit1.Text) then label1.Caption:='Is Proxy'
else label1.Caption:='Is not proxy';
end;
 
end.

Open in new window

set the handleredirects property of idhttp to true.
Another error now: EConvertError --> 'Invalid Argument to Date Encode'
Hmm never mind... It just get errors when i run it through Delphi... When i compile it, it runs ok!!
 
Thanks ciuly.
some errors will hapen because the connected server is not a proxy, but some can be because of normal conditions. like that 302, which is a redirect. that you needed to fix, because google.com redirects to your local google server, if there is one. other serves might redirect too. there can be other http rpotocol specific errors whciih do not mean that the connected server is not a proxy. but if yuo use the same server to test with (like google) I don't think ther ewill be any other errors which would give false results.