Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Send a Wake-on-LAN Magic Packet

See more Socket/SSL/TLS Examples

Demonstrates Socket.SendWakeOnLan, which sends a Wake-on-LAN magic packet for a MAC address to a UDP broadcast address and port.

Background. The MAC address is six bytes written as hexadecimal. Wake-on-LAN wakes a powered-down machine on the local network that has the feature enabled.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Socket;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  socket: TSocket;

begin
  success := False;

  socket := TSocket.Create;

  //  Send a Wake-on-LAN magic packet to wake a machine by its MAC address.  The MAC is six bytes
  //  written as hexadecimal, and the packet is sent to the UDP broadcast address and port.
  success := socket.SendWakeOnLan('000102030405',9,'255.255.255.255');
  if (success = False) then
    begin
      WriteLn(socket.LastErrorText);
      Exit;
    end;
  WriteLn('Wake-on-LAN packet sent.');


  socket.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.