Solved

Test if proxy server is ok.

Posted on 2006-11-09
12
1,992 Views
Last Modified: 2008-03-15
Hi,

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

Thank you!
0
Comment
Question by:crystyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 17911293
what defines if it's "ok"?
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 17911956
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
 

Author Comment

by:crystyan
ID: 17914562
Johnjces where should I put the proxy address and port ? I have idTCPClient

Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Johnjces
ID: 17919795
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
 
LVL 18

Expert Comment

by:Johnjces
ID: 17919807
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
 
LVL 18

Expert Comment

by:Johnjces
ID: 17924145
Did I help you?

JJ
0
 

Author Comment

by:crystyan
ID: 17924773
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
 
LVL 18

Expert Comment

by:Johnjces
ID: 17927254
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
 

Author Comment

by:crystyan
ID: 17927301
what do you mean ?
0
 
LVL 18

Accepted Solution

by:
Johnjces earned 500 total points
ID: 17927620
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
 
LVL 1

Expert Comment

by:Computer101
ID: 21133157
Forced accept.

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question