Thema: Delphi Wake on LAN

Einzelnen Beitrag anzeigen

Benutzerbild von seim
seim

Registriert seit: 11. Nov 2007
83 Beiträge
 
#24

Re: Wake on LAN

  Alt 1. Okt 2008, 11:09
Ich hab das nochmal durchgeguckt und bin zu folgendem funktionierenden Code gekommen:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    IdUDPClient1: TIdUDPClient;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{
What's a Magic Packet?
Was ist ein Magic Packet?

DESTINATION SOURCE MISC. FF FF FF FF FF FF 11 22 33 44 55 66 11 22 33 44
55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44
55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44
55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44
55 66 11 22 33 44 55 66 11 22 33 44 55 66 MISC. CRC.

Note: Destination, Source, Misc and CRC are normally added by our Socket-Component
Beachte: Destination, Source, Mis und CRC werden normalerweise von deiner
Socket-Komponente hinzugefügt
}


procedure TForm1.Button1Click(Sender: TObject);
var
  Data, temp: string;
  k, n: integer;
begin
  Data := '';
  for k := 0 to 5 do
  begin
    Data := Data + Chr(StrToInt('$FF')); // 6x add a FF / 6x ein FF hinzufügen
  end;
  temp := StringReplace(Edit1.Text, '-', '', [rfReplaceAll]);
  for k := 0 to 15 do
  begin
    temp := StringReplace(Edit1.Text, '-', '', [rfReplaceAll]);
    for n := 0 to 5 do
    begin
      // 16x add Target-Mac-Adress / 16x die Ziel-Macadresse hinzufügen
      Data := Data + Chr(StrToInt('$' + temp[1] + temp[2]));
      Delete(temp, 1, 2);
    end;
  end;
  
  //Example with TIdUDPClient of Indy
  IdUDPClient1.Host:= '255.255.255.255';
  IdUDPClient1.Port:= 80;
  IdUDPClient1.Send(Data); // Send it / Verschick es
end;

end.
Hier die .dfm (also alles was quasi in der Fensteransicht eingestellt wurde)
Delphi-Quellcode:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 294
  ClientWidth = 562
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 216
    Top = 120
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 168
    Top = 80
    Width = 249
    Height = 21
    TabOrder = 1
    Text = 'aa-bb-cc-dd-ee-ff'
  end
  object IdUDPClient1: TIdUDPClient
    BroadcastEnabled = True
    Port = 80
    Left = 424
    Top = 216
  end
end
Damit Wake On Lan funktioniert muss die Funktion natürlich im Bios des betreffenden Rechners aktiviert sein. Außerdem endet ein solcher Boardcast beim Router, wenn ihr also in ein anderes Subnetz wollt um ein Rechner zu booten, dann weis ich jetzt spontan auch nicht weiter.. Jedenfalls geht das Programm bei mir.
Angehängte Dateien
Dateityp: zip wol_288.zip (274,0 KB, 52x aufgerufen)
  Mit Zitat antworten Zitat