User Tools

Site Tools


windows:autoit:wake_on_lan

Send a WOL packet to a machine via. AutoIT.

CheckInPCWOL.au3
; Network broadcast address
$IPAddress = "192.168.222.255"; This is the broadcast address !
 
; MAC address of the machine
$MACAddress = "0000000000"
 
; Hostname of the PC
$Hostname = "CheckInPC"
 
; Status variables - No messing with this!
$SuccessFullWOL = 0
$LoopCount = 0
 
While ($SuccessFullWOL = 0)
 
	If $LoopCount > 5 Then
		MsgBox("WOL error", "Tried to start the PC " & $LoopCount & " times, but without success :(")
	EndIf
 
	UDPStartUp()
 
	$connexion = UDPOpen($IPAddress, 7)
	$res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
 
	UDPCloseSocket($connexion)
	UDPShutdown()
 
; Wait for the PC to boot, then ping it to see if it's up.
	Sleep(300000)
 
	$Pong = Ping ($hostname)
 
	If $Pong > 0 Then
		$SuccessFullWOL = 1
	EndIf
 
	$LoopCount = $LoopCount + 1	
 
WEnd
 
; ===================================================================
; Functions
; ===================================================================
 
; This function convert a MAC Address Byte (e.g. "1f") to a char
Func HexToChar($strHex)
	Return Chr(Dec($strHex))    
EndFunc
 
; This function generate the "Magic Packet"
Func GenerateMagicPacket($strMACAddress)
 
	$MagicPacket = ""
	$MACData = ""
 
	For $p = 1 To 11 Step 2
		$MACData = $MACData & HexToChar(StringMid($strMACAddress, $p, 2))
	Next
 
	For $p = 1 To 6
		$MagicPacket = HexToChar("ff") & $MagicPacket
	Next
 
	For $p = 1 To 16
		$MagicPacket = $MagicPacket & $MACData
	Next
 
	Return $MagicPacket
 
EndFunc
windows/autoit/wake_on_lan.txt · Last modified: 2015/08/15 22:56 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki