Networking, Pascal

Wake On Lan v Pascalu

{$A+,B-,C-,D-,E-,F-,G+,H-,I-,J+,K-,L-,M-,N+,O-,Q-,R-,S-,T-,V-,W-,X+,Y-}
 
program wake_on_lan;
 
uses Sockets, Winsock;
 
var
 
udaj : packed record
znacka : array [0..5] of byte;
mac : array[0..15, 0..5] of byte;
end;
 
i, x, y : integer;
addr : sockaddr_in;
S : cardinal;
delka : integer;
retezec : string;
cislo : byte;
optval : longint = 1;
 
begin
if paramcount <> 1 then
halt;
Retezec := UpCase(ParamStr(1));
with Udaj do
 begin
 for i := 0 to 5 do
  begin
   case Retezec[i*2+1] of
   '0'..'9' : Cislo := Ord(Retezec[i*2+1])-48;
   'A'..'F' : Cislo := Ord(Retezec[i*2+1])-55;
   else Cislo := 0;
   end;
  Cislo := Cislo*16;
   case Retezec[i*2+2] of
   '0'..'9' : Inc(Cislo,Ord(Retezec[i*2+2])-48);
   'A'..'F' : Inc(Cislo,Ord(Retezec[i*2+2])-55);
    end;
   Mac[0,i] := Cislo;
  end;
 end;
 for i:=0 to 14 do
 move(udaj.mac[0,0],udaj.mac[i+1,0],6);
 FillByte(udaj.Znacka,SizeOf(udaj.Znacka), -1);
 S:=Socket (AF_INET,SOCK_DGRAM,0);
 if S <> 0 then
  begin
   addr.sin_addr.S_addr := inet_addr('255.255.255.255');
   addr.sin_port := htons(9);
   addr.sin_family := AF_INET;
   fpsetsockopt(s,SOL_SOCKET,SO_BROADCAST,@optval,SizeOf(optval));
   sendto(s, udaj, sizeof(udaj),0,addr, sizeof(addr));
  end;
end.

Více o WOL:
http://cs.wikipedia.org/wiki/Wake_on_LAN
http://www.samuraj-cz.com/clanek/wake-on-lan-lokalni-i-vzdaleny-subnet/

Napsat komentář

*

*povinné položky - email nebude zobrazen