[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Test if proxy server is ok.

Posted on 2006-11-09
12
Medium Priority
?
2,048 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
11 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Technology Partners: 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 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