Solved

HOw to check proxy in delphi

Posted on 2004-08-30
4
1,016 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 500 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

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

690 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