Test if proxy server is ok.

Hi,

I need a way of testing if a proxy is working or it's stopped/not available, etc.

Thank you!
crystyanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JohnjcesConnect With a Mentor Commented:
From a PC that is using the proxy server, or whatever PC you are using to check your proxy server, you set this PC up to go through the proxy. Then you simply check for connectivity to some web site through the proxy you are wanting to monitor. Simply change your port and IP to say google.com on the TIdTCPClient component. You see, if the proxy is down, you won't be able to connect.

Since the proxy wants to proxy port 8080 to the web on port 80, when you try to test the proxy using port 8080 it wants to proxy it to port 80 somewhere.

Anyway, just a thought.

Good luck!

JJ
0
 
BlackTigerXCommented:
what defines if it's "ok"?
0
 
JohnjcesCommented:
Most proxy servers use port 8080 so we will assume 8080. If something non standard then substitute your proxy's port.

Anyway, in Delphi 5, a component is available called ClientSocket. An Indy alternative "might" be the idTCPClient. Haven't tested it but should be similar if you do not use D5.

Anyway, just set your port and your proxy's IP, make the component active and respond to the events OnConnect OnError and OnDisconnect.

If you connect, all "should" be active as far as the proxy port and communication. If error, then it is dead..

Good luck and hope this helped.

JJ
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
crystyanAuthor Commented:
Johnjces where should I put the proxy address and port ? I have idTCPClient

Thanks
0
 
JohnjcesCommented:
Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IdTCPClient1: TIdTCPClient;
    procedure IdTCPClient1Connected(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure IdTCPClient1Status(ASender: TObject;
      const AStatus: TIdStatus; const AStatusText: String);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IdTCPClient1Connected(Sender: TObject); //On connect event. If good do stuff here.
begin
 ShowMessage('Connected!');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPClient1.Host := 'Your Proxys IP)
IdTCPClient1.Port := 8080
 try
  IdTCPClient1.Connect(1000);
   except on E:exception do
    begin
     showmessage('Dead');
     // other stuff you might want to do.
    end;
 end;
end;

procedure TForm1.IdTCPClient1Status(ASender: TObject;   // Informational.
  const AStatus: TIdStatus; const AStatusText: String);
begin
 ShowMessage(AStatusText);
end;

end.

Since there is no OnError in the Indy comp we must trap the error if it is dad, it being your proxy.

Let me know.

John
0
 
JohnjcesCommented:
Also, don't forget to disconnect after a successful connect.

such as the following in the button

procedure TForm1.Button1Click(Sender: TObject);
begin
 IdTCPClient1.Host := '192.168.0.20';
 IdTCPClient1.Port := 80;
 try
  IdTCPClient1.Connect(1000);
   except on E:exception do
    showmessage('Bad stuff');
 end;
 IdTCPClient1.Disconnect;
end;
0
 
JohnjcesCommented:
Did I help you?

JJ
0
 
crystyanAuthor Commented:
yeah, but I'm still making tests ... it's weird because either all my proxies don't work, either it works only the port 80 to test ...
0
 
JohnjcesCommented:
A thought came to mind. A proxy server forwards all http port 80 and others like ftp ports and stuff on. So, when  trying to connect to it via port 8080 it will want to forward that request on to somewhere beyond the proxy!

So, you could test your proxy by connecting to a web server like google. If that works and you connect, then the proxy is working.

JJ
0
 
crystyanAuthor Commented:
what do you mean ?
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
All Courses

From novice to tech pro — start learning today.