Solved

HOw to check proxy in delphi

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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