Solved

HOw to check proxy in delphi

Posted on 2004-08-30
4
938 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
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Evarest
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

8 Experts available now in Live!

Get 1:1 Help Now