Board index » delphi » Wake-On-LAN API?

Wake-On-LAN API?


2003-08-06 03:22:59 PM
delphi4
Dear All,
I need to write a procedure to allow me to send a wake-on-lan message to a
favorite host in the network. Anyone has experience with that?
Any suggestion will be welcome.
Thx,
Eugen
 
 

Re:Wake-On-LAN API?

Eugen Mihailescu <XXXX@XXXXX.COM>wrote in article
<3f30acbc$XXXX@XXXXX.COM>...
Quote

I need to write a procedure to allow me to send a wake-on-lan message to
a
favorite host in the network. Anyone has experience with that?
Any suggestion will be welcome.

Eugen

There's no API per say, you need to send a specifically formatted broadcast
on the local segment. Do a google search on AMD Magic Packet.
The format is basically 6x$FF 16xMAC Address (48bit).
Here's a quick test I wrote a while ago. You won't have access to
TOysterSocket, use your favourate socket implementation ;) and create a UDP
socket. The rest should work if you have access to the standard socket
handle. Change the MAC address to match your requirements. And don't forgot
to make sure that the target machine supports WOL, and is enabled!
HTH
D.
var
Socket : TOysterSocket;
N : Integer;
destAddr : TSockAddr;
S : String;
begin
if CreateSocket(Socket,True) = 0 then
begin
N:=1;{SO_BROADCAST = True}
SetSockOpt(Socket.hSocket, SOL_SOCKET, SO_BROADCAST,@N, 4);
destAddr.sin_family:=AF_INET;
destAddr.sin_port:=htons(0);
destAddr.sin_addr.s_addr:=Integer(INADDR_BROADCAST);
S:=#255#255#255#255#255#255; {6x$FF}
for n:=1 to 16 do {16x(IEEE/MAC address 48bit)}
S:=S+char($00)+char($50)+char($8D)+char($48)+char($08)+char($D7);
N:=SizeOf(DestAddr);
N:=winsock.sendto(Socket.hSocket, S[1], Length(S), 0, DestAddr, N);
CloseSocket(@Socket,True);
end;
end;
--
The supplied email address is a spam trap, I don't read any mail sent to it
and I wipe it intermittently. I may be a bit backwards but you can contact
me here: eiTODtenitTAzad
 

Re:Wake-On-LAN API?

Eugen Mihailescu writes:
Quote
I need to write a procedure to allow me to send a wake-on-lan message to a
favorite host in the network. Anyone has experience with that?
Any suggestion will be welcome.
Synapse have function for this. ;-)
--
Lukas Gebauer.
www.ararat.cz/synapse/ - Synapse Delphi and Kylix TCP/IP Lib.