?
Solved

HOw to check proxy in delphi

Posted on 2004-08-30
4
Medium Priority
?
1,040 Views
Last Modified: 2010-04-05
Hello experts,

i need fast method that could check http proxy server status.
somth like this:

function check(proxy : string, port : word) : boolean;

returns true if proxy is working.

Thanks.


0
Comment
Question by:ccsking
[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
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Evarest
ID: 11931394
This code should do the trick:

NOTE: it requires INDY components to be installed. You can download these excellent components for free from

http://www.indyproject.org/download/Borland.html

[BEGIN CODE]

uses
  IdHTTP;

function check(proxy : string; port : word) : boolean;
var
 IdHTTP: TIdHTTP;
begin
 result :=false;
 with TIdHTTP.Create(nil) do
  begin
   ProxyParams.ProxyServer :=proxy;
   ProxyParams.ProxyPort :=Port;
   try
    Get('http://www.google.com');
    result :=true;
   except
   end;
   Free;
  end;
end;

[END CODE]

I check for http://www.google.com as this site is online for the most time :-)

Hope to help...
Evarest
0
 

Author Comment

by:ccsking
ID: 11932302
it is good method but not fast becouse it needs to download data from webpage.
i think it should be the faster way to check proxy
am i right?
0
 

Author Comment

by:ccsking
ID: 11932385
and another thing: method "get" is not very good if you want to check several proxies at same time
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 2000 total points
ID: 11932523
I put together this demo for you:

Source:
=====

unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Sockets, StdCtrls;

type
  TForm1 = class(TForm)
    btnCheckConn: TButton;
    Label1: TLabel;
    Label2: TLabel;
    inpHost: TEdit;
    inpPort: TEdit;
    Memo1: TMemo;
    procedure btnCheckConnClick(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function CheckConn(host: string; port : word) : boolean;
var TcpClient1: TTcpClient;
begin
  try
    TcpClient1:= TTcpClient.Create(self);
    TcpClient1.RemoteHost:= Host;
    TcpClient1.RemotePort:= IntToStr(port);
    if TcpClient1.Connect
      then begin
           result:= true;
           TcpClient1.Disconnect;
      end
      else result:= false;
  finally
    TcpClient1.Free;
  end;
end;

procedure TForm1.btnCheckConnClick(Sender: TObject);
begin
  if CheckConn(inpHost.Text, StrToInt(inpPort.Text)) then
    then Memo1.Lines.Add('Connection to '+TcpClient1.RemoteHost+
                         ' succeeded on port: '+TcpClient1.RemotePort);
    else Memo1.Lines.Add('Connection to '+TcpClient1.RemoteHost+
                         ' failed on port: '+TcpClient1.RemotePort);
end;

end.


DFM File
======
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 339
  Height = 259
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  DesignSize = (
    331
    225)
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 16
    Width = 22
    Height = 13
    Caption = 'Host'
  end
  object Label2: TLabel
    Left = 24
    Top = 40
    Width = 19
    Height = 13
    Caption = 'Port'
  end
  object btnCheckConn: TButton
    Left = 80
    Top = 80
    Width = 89
    Height = 25
    Caption = 'Check Connect'
    Default = True
    TabOrder = 2
    OnClick = btnCheckConnClick
  end
  object inpHost: TEdit
    Left = 80
    Top = 16
    Width = 236
    Height = 21
    Anchors = [akLeft, akTop, akRight]
    TabOrder = 0
  end
  object inpPort: TEdit
    Left = 80
    Top = 40
    Width = 236
    Height = 21
    Anchors = [akLeft, akTop, akRight]
    TabOrder = 1
  end
  object Memo1: TMemo
    Left = 16
    Top = 120
    Width = 300
    Height = 89
    Anchors = [akLeft, akTop, akRight]
    TabOrder = 3
  end
end

Kind regards
Pierre
0

Featured Post

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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