Solved

HOw to check proxy in delphi

Posted on 2004-08-30
4
979 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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