1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
   | unit Unit1;
 
interface
 
uses
  Windows, SysUtils, Graphics, Forms, Controls, Classes, StdCtrls, ExtCtrls, ShellApi,
  IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient;
 
type
  TDonnee = record
    DateTime: TDateTime;
    Connexion: Boolean;
  end;
  TForm1 = class(TForm)
    pinger: TIdIcmpClient;
    Timer1: TTimer;
    Label1: TLabel;
    Shape1: TShape;
    LabelConnexion: TLabel;
    Label2: TLabel;
    LabelMesure: TLabel;
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Afficher;
    procedure AjouterLigneMemo(Value: TDonnee);
  private
    Donnees: array[0..10000] of TDonnee;
    Mesure: integer;
  public
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  pinger.Host := '66.102.11.104'; // google --> http://www.webrankinfo.com/google/data-centers.php
  pinger.ReceiveTimeout := 3000;
  Timer1.Interval := pinger.ReceiveTimeout + 2000;
 
  Memo1.Clear;
  Mesure := 0;
 
  Donnees[Mesure].DateTime := Now;
  pinger.Ping;
  Donnees[Mesure].Connexion := not (pinger.ReplyStatus.ReplyStatusType=rsTimeOut);
  AjouterLigneMemo(Donnees[Mesure]);
 
  Afficher;
end;
 
procedure TForm1.Timer1Timer(Sender: TObject);
var Donnee: TDonnee;
begin
  Caption := 'Test en cours...';
 
  Donnee.DateTime  := Now;
  pinger.Ping;
  Donnee.Connexion := not (pinger.ReplyStatus.ReplyStatusType=rsTimeOut);
 
  if not (Donnees[Mesure].Connexion=Donnee.Connexion)
    then begin
      Inc(Mesure);
      Donnees[Mesure] := Donnee;
      AjouterLigneMemo(Donnees[Mesure]);
    end;
 
  Afficher;
end;
 
procedure TForm1.Afficher;
begin
  Caption := 'En attente du prochain test';
 
  LabelMesure.Caption := IntToStr(Mesure);
 
  if Donnees[Mesure].Connexion
    then begin
      LabelConnexion.Caption := 'Connecté';
      Shape1.Brush.Color := ClGreen;
    end
    else begin
      LabelConnexion.Caption := 'Déconnecté';
      Shape1.Brush.Color := ClRed;
    end;
end;
 
procedure TForm1.AjouterLigneMemo(Value: TDonnee);
var TexteConnexion: string;
begin
  if Value.Connexion
    then TexteConnexion := 'Connecté'
    else TexteConnexion := 'Déconnecté';
  Memo1.Lines.Strings[Mesure] := DateTimeToStr(Value.DateTime)+#9+TexteConnexion;
  Memo1.Lines.Add('');
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(0, 'Open', Pchar('http://'+pinger.Host), nil, nil, SW_SHOW);
end;
 
end. | 
Partager