Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Implementation of "Wake On Lan" procedure (WOL) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Implementation of "Wake On Lan" procedure (WOL) 03-Oct-04
Category
Internet / Web
Language
Delphi All Versions
Views
790
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Heydon, Mike
Reference URL:
			Question/Problem/Abstract:

This procedure will switch on a machine that is connected to a LAN. The MAC address 
of the machine is needed to be known. 
See my article ("http://www.delphi3000.com/articles/article_3867.asp") for a 
function GetMacAddress() that returns a MAC Address String. 

The "Wake On Lan" feature of the machine's BIOS must be enabled. 

The procedure works by broadcasting a UDP packet containing the "Magic Number" to 
all machines on the LAN. The machine with the MAC address, if switched of and BIOS 
WOL enabled will wake up and boot. 

The MAC address required is a "-" delimited 17 char string. 
Example : 
1   
2   WakeOnLan('00-D0-B7-E2-A1-A0');

 
Answer:

3   
4   uses idUDPClient; 
5   
6   // ========================================================================== 
7   // Wakes a machine on lan 
8   // AMacAddress is 17 char MAC address. 
9   // eg.  '00-C0-4F-0A-3A-D7' 
10  // ========================================================================== 
11  
12  procedure WakeOnLan(const AMacAddress : string); 
13  type 
14       TMacAddress = array [1..6] of byte; 
15  
16       TWakeRecord = packed record 
17         Waker : TMACAddress; 
18         MAC   : array[0..15] of TMACAddress; 
19       end; 
20  
21  var i : integer; 
22      WR : TWakeRecord; 
23      MacAddress : TMacAddress; 
24      UDP : TIdUDPClient; 
25      sData : string; 
26  begin 
27    // Convert MAC string into MAC array 
28    fillchar(MacAddress,SizeOf(TMacAddress),0); 
29    sData := trim(AMacAddress); 
30  
31    if length(sData) = 17 then begin 
32      for i := 1 to 6 do begin 
33        MacAddress[i] := StrToIntDef('$' + copy(sData,1,2),0); 
34        sData := copy(sData,4,17); 
35      end; 
36    end; 
37  
38    for i := 1 to 6 do WR.Waker[i] := $FF; 
39    for i := 0 to 15 do WR.MAC[i] := MacAddress; 
40    // Create UDP and Broadcast data structure 
41    UDP := TIdUDPClient.Create(nil); 
42    UDP.Host := '255.255.255.255'; 
43    UDP.Port := 32767; 
44    UDP.BroadCastEnabled := true; 
45    UDP.SendBuffer(WR,SizeOf(TWakeRecord)); 
46    UDP.BroadcastEnabled := false; 
47    UDP.Free; 
48  end; 



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC