Solved

Test if proxy server is ok.

Posted on 2006-11-09
12
1,962 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
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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now