unit uWakeOnLan;
interface
implementation
uses
WinTypes, Messages, SysUtils, Classes, IdBaseComponent,
IdComponent, IdUDPBase, IdUDPClient;
Function HexToInt(S:
String): LongInt;
const
DecDigits:
Set Of '
0'..'
9' = ['
0'..'
9'];
HexVals:
Array [0..$F]
Of Integer = (0, 1, 2, 3, 4, 5, 6, 7,
8, 9, $A, $B, $C, $D, $E, $F);
UpCaseHexLetters:
Set Of '
A'..'
F' = ['
A'..'
F'];
LowCaseHexLetters:
Set Of '
a'..'
f' = ['
a'..'
f'];
var
v: LongInt;
i: integer;
LookUpIndex: integer;
begin
if length(S) <= 8
then
begin
v := 0;
for i := 1
to length(S)
do
begin
{$R-}
v := v
Shl 4;
{$R+}
if S[i]
in DecDigits
then
begin
LookUpIndex := Ord(S[i]) - Ord('
0');
end else
begin
if S[i]
in UpCaseHexLetters
then
begin
LookUpIndex := Ord(S[i]) - Ord('
A') + $A;
end else
begin
if S[i]
in LowCaseHexLetters
then
begin
LookUpIndex := Ord(S[i]) - Ord('
a') + $A;
end else
begin
LookUpIndex := 0;
end;
end;
end;
v := v
Or HexVals[LookUpIndex];
end;
result := v;
end else
begin
result := 0;
end;
end;
procedure WakeUPComputer(aMacAddress:
string);
var
i, j: Byte;
lBuffer:
array[1..116]
of Byte;
lUDPClient: TIdUDPClient;
bs: TBytes;
begin
try
SetLength(bs, 116);
for i := 0
to 5
do
begin
bs[i] := HexToInt(aMacAddress[(i * 2) - 1] + aMacAddress[i * 2]);
end;
bs[6] := $00;
bs[7] := $74;
bs[8] := $FF;
bs[9] := $FF;
bs[10] := $FF;
bs[11] := $FF;
bs[12] := $FF;
bs[13] := $FF;
for j := 1
to 16
do
begin
for i := 1
to 6
do
begin
bs[14 + (j - 1) * 6 + (i - 1)] := bs[i];
end;
end;
bs[115] := $00;
bs[114] := $40;
bs[113] := $90;
bs[112] := $90;
bs[111] := $00;
bs[110] := $40;
try
lUDPClient := TIdUDPClient.Create(
nil);
lUDPClient.BroadcastEnabled := true;
lUDPClient.Host := '
255.255.255.255';
lUDPClient.Port := 2050;
lUDPClient.SendBuffer(lUDPClient.Host, lUDPClient.Port, bs);
// <-- hier das Problem
writeln('
Trying to wake-up remote host: ' + aMacAddress);
finally
lUDPClient.Free;
end;
except
on E:
Exception do writeln('
There was an error');
end;
end;
end.