interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WinSock, StdCtrls, ExtCtrls, WinSkinData, SUIForm;
type
TForm1 = class(TForm)
suiForm1: TsuiForm;
Label1: TLabel;
Label2: TLabel;
Bevel1: TBevel;
Memo1: TMemo;
Edit1: TEdit;
Button2: TButton;
Timer1: TTimer;
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
IPINFO = record
Ttl :char;
Tos :char;
IPFlags :char;
OptSize :char;
Options :^char;
end;
type
ICMPECHO = record
Source :longint;
Status :longint;
RTTime :longint;
DataSize:Shortint;
Reserved:Shortint;
pData :^variant;
i_ipinfo:IPINFO;
end;
TIcmpCreateFile = function():integer; {$IFDEF WIN32} stdcall; {$ENDIF}
TIcmpCloseHandle = procedure(var handle:integer);{$IFDEF WIN32} stdcall; {$ENDIF}
TIcmpSendEcho = function(var handle:integer; endereco:DWORD; buffer:variant; tam:WORD; IP:IPINFO; ICMP:ICMPECHO; tamicmp:DWORD; tempo:DWORD):DWORD;{$IFDEF WIN32} stdcall; {$ENDIF}
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
wsadt : wsadata;
icmp : icmpecho;
HNDicmp : integer;
Host : PHostEnt;
Destino : in_addr;
IP : ipinfo;
Retorno : integer;
x : integer;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle : TIcmpCloseHandle;
IcmpSendEcho : TIcmpSendEcho;
begin
Memo1.Clear;
if (edit1.Text = '') then
begin
edit1.Text:='localhost';
exit;
end;
HNDicmp := LoadLibrary('ICMP.DLL');
if (HNDicmp <> 0) then
begin
@IcmpCreateFile := GetProcAddress(HNDicmp,'IcmpCreateFile');
@IcmpCloseHandle := GetProcAddress(HNDicmp,'IcmpCloseHandle');
@IcmpSendEcho := GetProcAddress(HNDicmp,'IcmpSendEcho');
if (@IcmpCreateFile=nil) or (@IcmpCloseHandle=nil) or (@IcmpSendEcho=nil) then
begin
Application.MessageBox('Error getting ICMP Adress','error', MB_OK);
FreeLibrary(HNDicmp);
end;
end;
Retorno := WSAStartup($0101,wsadt);
if (Retorno <> 0) then
begin
Application.MessageBox('Can´t Load WinSockets','WSAStartup', MB_OK);
WSACleanup();
FreeLibrary(HNDicmp);
end;
Destino.S_addr := inet_addr(Pchar(Edit1.text));
if (Destino.S_addr = 0) then
Host := GetHostbyName(PChar(Edit1.text))
else
Host := GetHostbyAddr(@Destino,sizeof(in_addr), AF_INET);
if (host = nil) then
begin
memo1.Clear;
//MessageDlg('IP yang anda maksudkan tidak diketemukan...',mtInformation,[mbOK],0);
memo1.Lines.Add('Tidak bisa koneksi ke '+ edit1.Text );
memo1.Lines.Add('Tidak bisa koneksi ke '+ edit1.Text );
memo1.Lines.Add('Tidak bisa koneksi ke '+ edit1.Text );
memo1.Lines.Add('Tidak bisa koneksi ke '+ edit1.Text );
memo1.Lines.Add('Tidak bisa koneksi ke '+ edit1.Text );
WSACleanup();
FreeLibrary(HNDicmp);
exit;
end;
for x:= 0 to 4 do
begin
Ip.Ttl := char(255);
Ip.Tos := char(0);
Ip.IPFlags := char(0);
Ip.OptSize := char(0);
Ip.Options := nil;
Destino.S_addr := icmp.source;
if (edit1.Text = '') then
Memo1.Lines.Add('Cek Koneksi IP localhost Lancar')
else
Memo1.Lines.Add('Cek Koneksi IP ' + Edit1.text + ' Lancar');
end;
FreeLibrary(HNDicmp);
WSACleanup();
end;
end.
Sekarang rekan-rekan bisa mencobanya semoga bermanfaat.