unit PingU;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, IdComponent, IdRawBase, IdRawClient, IdIcmpClient,
Vcl.StdCtrls,
IdBaseComponent, System.UITypes,
Vcl.ExtCtrls;
type
TPing =
class(TForm)
lstreplies: TListBox;
ICMP: TIdIcmpClient;
btnPing: TButton;
edt_host1: TLabeledEdit;
edt_host2: TLabeledEdit;
edCount: TLabeledEdit;
procedure btnPingClick(Sender: TObject);
procedure ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Ping: TPing;
implementation
{$R *.dfm}
procedure TPing.ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
var
sTime:
string;
formattedDateTime :
string;
begin
// Antwort - Zeit überprüfen
if (ICMP.ReplyStatus.MsRoundTripTime = 0)
then
sTime := '
<1'
else
sTime := '
=';
// Füge der Listbox die Items hinzu
datetimetostring(formattedDateTime, '
dd.mm.yyyy hh:mm:ss', now());
lstReplies.Items.Add(formattedDateTime + '
- ' + Format('
Antwort von %s: Bytes=%d Zeit%s%dms TTL=%d',
[ICMP.ReplyStatus.FromIpAddress,
ICMP.ReplyStatus.BytesReceived,
sTime,
ICMP.ReplyStatus.MsRoundTripTime,
ICMP.ReplyStatus.TimeToLive]));
end;
procedure TPing.btnPingClick(Sender: TObject);
var
i: integer;
formattedDateTime :
string;
IP, Land :
string;
begin
// Listbox leeren
lstReplies.Clear;
// Ereignis 'OnReply' festlegen
ICMP.OnReply := ICMPReply;
// ReceiveTimeout einstellen
ICMP.ReceiveTimeout := 1000;
// Button Ping auf Enabled=False setzen
btnPing.Enabled := False;
// Ping starten
//
... Land und
IP wird hier definiert, muss ich hier aber raus kürzen
//
lstReplies.Items.Add('
Filiale : ' + edt_host1.Text);
lstReplies.Items.Add('
Gerät : ' + edt_host2.Text);
lstReplies.Items.Add('
IP : ' +
IP);
lstReplies.Items.Add('
Dauer : ' + edCount.Text + '
Min. = ' + inttostr(strtoint(edCount.text)*60) + '
Pings');
lstreplies.TopIndex := lstreplies.Items.Count-1;
try
// Host festlegen
ICMP.Host :=
IP;
// Ping so oft durchführen wie bei 'Anzahl der Pings' festgelegt
for i := 1
to strtoint(edCount.text)*60
do begin
Sleep(1000);
datetimetostring(formattedDateTime, '
dd.mm.yyyy hh:mm:ss', now());
try
// Ping senden
ICMP.Ping;
// Nachrichten verarbeiten
Application.ProcessMessages;
lstreplies.TopIndex := lstreplies.Items.Count-1;
except
lstReplies.Items.Add(formattedDateTime + '
- ' + '
Zeitüberschreitung der Anforderung');
lstreplies.TopIndex := lstreplies.Items.Count-1;
end;
end;
finally
// Button Ping wieder auf Enabled=True
btnPing.Enabled := True;
end;
end;
end.