unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TThread =
record
ID: cardinal;
Handle: THandle;
Result: cardinal;
end;
IPAddr = DWORD;
PICMP_ECHO_REPLY = ^ICMP_ECHO_REPLY;
ICMP_ECHO_REPLY =
packed record
Address : ULONG;
Status : ULONG;
RoundTripTime : ULONG;
DataSize : WORD;
Reserved : WORD;
Data : Pointer;
end;
PIP_OPTION_INFORMATION = ^IP_OPTION_INFORMATION;
IP_OPTION_INFORMATION =
packed record
Ttl : byte;
Tos : byte;
Flags : byte;
OptionsSize : byte;
OptionsData : Pointer;
end;
function IcmpCreateFile : DWORD;
stdcall;
external '
icmp.dll';
function IcmpCloseHandle(
const IcmpHandle : DWORD) : longbool;
stdcall;
external '
icmp.dll';
function IcmpSendEcho(
const IcmpHandle : DWORD;
const DestinationAddress : IPAddr;
const RequestData : Pointer;
const RequestSize : WORD;
const RequestOptions : PIP_OPTION_INFORMATION;
const ReplyBuffer : Pointer;
const ReplySize : DWORD;
const TimeOut : DWORD) : DWORD;
stdcall;
external '
icmp.dll';
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function PingThread(p:pointer):cardinal;
var
hICMP : DWORD;
pierWork : PICMP_ECHO_REPLY;
dwSize : DWORD;
begin
hICMP := IcmpCreateFile;
if hICMP = INVALID_HANDLE_VALUE
then exit;
try
dwSize := SizeOf(ICMP_ECHO_REPLY)+8;
pierWork := AllocMem(dwSize);
try
result:=IcmpSendEcho(hICMP,MAKELONG(MAKEWORD(192, 168),MAKEWORD(1, 1)),
nil,0,
nil,pierWork,dwSize,1000);
finally
FreeMem(pierWork,dwSize);
end;
finally
IcmpCloseHandle(hIcmp);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
Threadarray:
array[0..128]
of TThread;
running: boolean;
StartTime, EndTime: DWORD;
begin
FillChar(Threadarray, sizeof(Threadarray),#0);
running:=true;
for i:=low(Threadarray)
to High(Threadarray)
do
begin
Threadarray[i].Handle:=CreateThread(
nil,0,@PingThread,
nil,0,Threadarray[i].ID);
Threadarray[i].ID:=259;
end;
StartTime:=GetTickCount;
while running
do
begin
running:=false;
for i:=low(Threadarray)
to High(Threadarray)
do
begin
Application.ProcessMessages;
if Threadarray[i].ID=259
then
begin
GetExitCodeThread(Threadarray[i].Handle, Threadarray[i].Result);
running:=true;
end
else
CloseHandle(Threadarray[i].Handle);
end;
end;
EndTime:=GetTickCount;
ShowMessage(inttostr(32* (high(Threadarray)-low(Threadarray)))+'
bytes in '+ inttostr(EndTime-StartTime)+'
ms');
ShowMessage(inttostr((1000
div (EndTime - StartTime))* 32* (high(Threadarray)-low(Threadarray)))+'
bytes in '+ inttostr(1000)+'
ms');
end;
end.