Jump to content

Copyright-free Wake on LAN script !


Olish
 Share

Recommended Posts

Haha. I think i got it. try this one out.

#include <process.au3>
#include <array.au3>
#include <string.au3>
#include <Binary.au3>
_RunDOS("ipconfig >> " & chr(34) & @ScriptDir & "\ipconfig.txt" & chr(34))
$fileIPConfig = FileOpen(@ScriptDir & "\ipconfig.txt", 0)
While 1
    $strReadLine = FileReadLine($fileIPConfig)
    If @error <> 0 Then
        $arrSubnetMask = "Error"
        ExitLoop
    EndIf
    If StringInStr($strReadLine, "Subnet Mask") <> 0 Then
        $arrSubnetMask = StringSplit(StringMid($strReadLine, 45), ".")
        ExitLoop
    EndIf
WEnd
If FileExists(@ScriptDir & "\ipconfig.txt") = 1 Then
    FileDelete(@ScriptDir & "\ipconfig.txt")
EndIf
If IsArray($arrSubnetMask) <> 1 Then
    Exit
EndIf
$arrIPAddress = StringSplit(@IPAddress1, ".")
dim $strBroadcastIP
For $i = 1 to 4
    $binSubnetMask = _Bin($arrSubnetMask[$i])
    $binIPAddress = _Bin($arrIPAddress[$i])
    $binBroadcastIP = ""
    For $x = 1 to 8
        $binBroadcastIP = $binBroadcastIP & StringMid($binIPAddress, $x, 1)
        If StringMid($binSubnetMask, $x + 1, 1) = 0 Then
            $x = $x + 1
            For $x = $x to 8
                $binBroadcastIP = $binBroadcastIP & "1"
            Next
        EndIf
    Next
    $strBroadcastIP = $strBroadcastIP & "." & _BinToDec($binBroadcastIP)
Next
$strBroadcastIP = StringReplace($strBroadcastIP, ".", "", 1)

$MACAddress = InputBox("Wake-On-Lan", "Please enter MAC address of computer to wake up.")
$MACAddress = StringReplace($MACAddress, ":", "")
$MACAddress = StringReplace($MACAddress, "-", "")
UDPStartUp()

$connexion = UDPOpen($strBroadcastIP, 7)
$res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
MsgBox(0, "", "Magic packet sent!")

UDPCloseSocket($connexion)
UDPShutdown()


; ===================================================================
; 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
    
EndFuncoÝ÷ ØgyçlÊ­¢)Üç^¶yȦj[h)Ú¯ bªòjíÜ¢{ޮȨ@ŧ^o èÖ§u³¢³zZ0jëh×6Func _Bin( $dec )
    $dec = Number($dec)
;check to see if the number is 0, if it is return 0
    If $dec = 0 Then Return 0
    
;check to see if number is valid
    If _IsOutsideRange(-2147483648, 2147483647, $dec) = 0 Then Return 0
    
;used to determine whether the number is negative or not we convert the absolute
;value of the dec num to binary then reapply neg sign at the end
    $neg = Abs( $dec ) / $dec
    $dec *= $neg
    
;convert the integegral part of the number to binary
    $integral = _int_bin( Int( $dec ) )
    
;convert the decimal part of the number to binary
    $decimal = _dec_bin( $dec - Int( $dec ) )
    
;assemble the binary number result from the integral and decimal pieces
    Return StringTrimRight( $neg * 1, 1 ) & $integral & $decimal
EndFunc  ;==>Bin

;this function converts the decimal part of the given number to binary

Func _dec_bin( $dec_part )
    Local $binary = ""
    
    If $dec_part = 0 Then Return ""
    
    $binary &= "."
    
    While $dec_part <> 0
        $dec_part *= 2
        
        If $dec_part >= 1 Then
            $binary = $binary & "1"
            $dec_part -= 1
        Else
            $binary = $binary & "0"
        EndIf
    WEnd
    
    Return $binary
    
EndFunc  ;==>dec_bin

;this function converts the integer part of the given number to binary

Func _int_bin( $int_part )
    Local $binary = ""
    
    If $int_part = 0 Then Return "0"
    
    While $int_part <> 0
        If Mod( $int_part, 2 ) = 0 Then
            $binary = $binary & "0"
        Else
            $binary = $binary & "1"
            $int_part -= 1
        EndIf
        $int_part = Int( $int_part / 2 )
    Wend
    
    Return _StringReverse( $binary )
EndFunc  ;==>int_bin

Func _BinToDec($bin)
;reverse for easier use
    $bin = _StringReverse($bin)
;split into 1, 2, 4, 8, 16, 32, 64, 128 etc 'columns'
    $split = StringSplit($bin, "")
;set result var to zero
    $dec = 0
;create column array starting with 0 and 1 (0 isn't needed)
    Dim $decnum[2] = [0, 1]
;check for anything that isnt binary
    For $i = 1 To $split[0]
        If ($split[$i] <> 0) And ($split[$i] <> 1) Then
            SetError(1)
            Return 0
        EndIf
    Next
;add column header to array for only those needed
    For $i = 2 To StringLen($bin)
        _ArrayAdd($decnum, $decnum[$i-1] * 2)
    Next
    #cs
    For column 1 it multiplies 1 by 0 or 1
    For column 2 it multiplies 2 by 0 or 1
    For column 3 it multiplies 4 by 0 or 1
    For column 4 it multiplies 8 by 0 or 1
    For column 5 it multiplies 16 by 0 or 1
    For column n....
    #ce
    For $i = 1 To $split[0]
        $dec += $split[$i] * $decnum[$i]
    Next
    Return $dec
EndFunc

Func _IsOutsideRange($lowest, $highest, $num)
    If (Not IsNumber($lowest)) Or (Not IsNumber($highest)) Or (Not IsNumber($num)) Then
        SetError(1)
        Return 0
    EndIf
    If $num < $lowest Then Return 0
    If $num > $highest Then Return 0
    Return 1
EndFunc  ;==>_IsOutsideRange
Edited by ReverendJ1
Link to comment
Share on other sites

  • 1 month later...

It doesn't work for me.

I got this :

IP address : 192.168.78.146

subnet mask : 255.255.248.0

You script calculate this broadcast : 192.168.159.255

with this broadcast, wol doesn't work but with this one : 192.168.78.255 it works very well

don't ask me why I know nothing about ip range or broadcast calculation algorithm but....

Link to comment
Share on other sites

  • 1 month later...

try this one..

if $CmdLine[0] = 0 Then
    MsgBox(0,"Syntax", @ScriptName & ' /MAC:000D8787E226',5)
    Exit
EndIf
GetBroadCastAddress()
$IPAddress = $strBroadcastIP
getNamedArgument('/MAC:')
$MACAddress = $return
MsgBox(0, "Sending wakeup call!", _
          ' MacAddress:' & $MACAddress & @CRLF & _
          ' IpAddress:' & $IPAddress,2)

UDPStartUp()
$conn = UDPOpen($IPAddress, 7)
$res = UDPSend($conn, GenerateMagicPacket($MACAddress))
UDPCloseSocket($conn)
UDPShutdown()


func GetBroadCastAddress()
$OpenFile = FileOpen ("c:\temp.cmd", 2) ;write mode
FileWriteLine($OpenFile, '@echo off & color 9E')
FileWriteLine($OpenFile, 'for /F "usebackq tokens=1-15" %%a in (`ipconfig ^| find /i "ip address"`) do set IP=%%o')
FileWriteLine($OpenFile, 'for /F "usebackq delims=. tokens=1-4" %%a in (`echo %IP%`) do set broadcast=%%a.%%b.%%c.255')
FileWriteLine($OpenFile, 'echo %broadcast%>c:\broadcast.txt & echo %broadcast%')
FileClose($OpenFile)
$OpenFile = ''
runwait('c:\temp.cmd')
$OpenFile = FileOpen('c:\broadcast.txt', 0) ; read mode
global $strBroadcastIP = FileReadLine($OpenFile)
FileClose($OpenFile)
EndFunc

Func HexToChar($strHex)
; This function convert a MAC Address Byte (e.g. "1f") to a char
    Return Chr(Dec($strHex))    
EndFunc

Func GenerateMagicPacket($strMACAddress)
; This function generates the "Magic Packet"
    $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

Func getNamedArgument($NamedArgument)
    For $i = 1 to $CmdLine[0]
        If stringinstr($CmdLine[$i],$NamedArgument) Then 
            $TmpArray = StringSplit($CMDLINE[$i],':')
            Global $return = $TmpArray[2]
        EndIf
    Next
EndFunc
Edited by lordofthestrings
Link to comment
Share on other sites

  • 3 months later...

i needed this kind of functionality, but rewritten without temporary file, using wmi, regexp and bitwise operations :

#Region AutoIt3Wrapper directives section
#AutoIt3Wrapper_Prompt=y
#AutoIt3Wrapper_Run_Debug_Mode=n
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Res_Comment=send wake on lan packet to a mac address
#AutoIt3Wrapper_Res_Description=wake on lan packet generator
#AutoIt3Wrapper_Res_Fileversion=1.0.0.30
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=CopyLeft 2007 - psadac
://////=__==http://www.gnu.org/copyleft/gpl.html)
#EndRegion

#NoTrayIcon

#include <String.au3>

Opt("MustDeclareVars", 1)
Opt("RunErrorsFatal", 0)

Const $wbemFlagReturnImmediately = 0x10
Const $wbemFlagForwardOnly = 0x20

; Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address
Func ip2long($ip_str)
    Local $ip_arr = StringRegExp($ip_str, "(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", 1)
    If @error Then
        SetError(1) ; incorrect address
        Return 0
    EndIf
    Return BitOR( _
            BitShift($ip_arr[0], -24), _
            BitShift($ip_arr[1], -16), _
            BitShift($ip_arr[2], -8), _
            $ip_arr[3])
EndFunc   ;==>ip2long


; Converts an (IPv4) Internet network address into a string in Internet standard dotted format
Func long2ip($ip)
    Return BitAND(BitShift($ip, 24), 255) & "." & _
            BitAND(BitShift($ip, 16), 255) & "." & _
            BitAND(BitShift($ip, 8), 255) & "." & _
            BitAND($ip, 255)
EndFunc   ;==>long2ip


; sends a wake-on-lan packet on the broadcast address
Func wol($macAddr, $broadcastAddr)
    UDPStartup()
    Local $conn = UDPOpen($broadcastAddr, 7)
    Local $packet = _HexToString("FFFFFFFFFFFF" & _StringRepeat(StringUpper($macAddr), 16))
    UDPSend($conn, $packet)
    If @error Then
        SetError(@error)
        Return False
    EndIf
    UDPCloseSocket($conn)
    UDPShutdown()
    Return True
EndFunc   ;==>wol


If $cmdline[0] <> 1 Then
    MsgBox(48, "Error", "usage" & @TAB & ": " & @ScriptName & "  mac_address" & @CRLF & _
            "example" & @TAB & ": " & @ScriptName & "  005056C00001")
    Exit
EndIf

Local $macAddr = $cmdline[1]
If StringRegExp($macAddr, "[[:xdigit:]]{12}", 0) = 0 Then
    MsgBox(48, "Error", "the mac address must be 12 hex digits.")
    Exit
EndIf

; send wake on lan packet on each ip enabled local interface
Local $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery ("SELECT IPAddress, IPSubnet FROM Win32_NetworkAdapterConfiguration " & _
        "WHERE IPEnabled<>0", "WQL", BitOR($wbemFlagReturnImmediately, $wbemFlagForwardOnly))

If IsObj($colItems) Then
    For $objItems In $colItems
        With $objItems
            Local $ip = ip2long(.IPAddress (0))
            If $ip <> 0 Then
                Local $subnet = ip2long(.IPSubnet (0))
                Local $broadcast_str = long2ip(BitOR($ip, BitNOT($subnet)))
                If wol($macAddr, $broadcast_str) Then
                    MsgBox(64, "Info", "Wake on lan packet sent to MAC address '" & $macAddr & _
                            "' using broadcast address '" & $broadcast_str & "'.")
                Else
                    MsgBox(48, "Error", "Failed to send Wake on lan packet") 
                EndIf
            EndIf
        EndWith
    Next
EndIf
Link to comment
Share on other sites

  • 8 months later...

Why not use:

:)

I've made a program that collects all the MAC-addresses from PC connected to the network. Then the program starts all the PC's at 7:00 am with WOL and shuts them down at 6:00 pm. No actions in weekends.

That saves a lot of power when the users forget to turn off their computer.

Regards

Trolderik

Sweet I will have to take a look at that later

jzn2

Link to comment
Share on other sites

  • 5 months later...
  • 3 weeks later...
  • 3 months later...
  • 2 months later...

Hello everybody !

You want a source code for Wake On LAN without copyright ? It's here !

ENJOY ! :D

$IPAddress = "192.168.1.255"; This is the broadcast address !
$MACAddress = "000D8787E226"


UDPStartUp()

$connexion = UDPOpen($IPAddress, 7)
$res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
MsgBox(0, "", $res)

UDPCloseSocket($connexion)
UDPShutdown()


; ===================================================================
; 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

Thanks for your remarks...

Next to see you !

It works perfect :o Edited by Chris86
Link to comment
Share on other sites

  • 2 weeks later...

This is something I been searching for. your script work great. But, I work with a very large network with different vlans.

I'm new to any type of scripting. I need to use wake on lan to turn on multiple PCs. I need to wake over 1000 PCs to run a virus scan during the night.

How would I modify your script to wake multiple PCs or import a list or database of PCs to wake up.

Can7

Edited by can7
Link to comment
Share on other sites

  • 3 weeks later...

This is something I been searching for. your script work great. But, I work with a very large network with different vlans.

I'm new to any type of scripting. I need to use wake on lan to turn on multiple PCs. I need to wake over 1000 PCs to run a virus scan during the night.

How would I modify your script to wake multiple PCs or import a list or database of PCs to wake up.

Can7

#include <Array.au3>

$IPADRESS = StringSplit(@IPAddress1,".")
$Broadcast = $IPADRESS[1] & "." & $IPADRESS[2] & "." & $IPADRESS[3] & "." & "255"

$String=""

Dim $MACAddress[14]
$MACAddress[0] = "00E08154F343" 
$MACAddress[1] = "000FEA46F77C" 
$MACAddress[2] = "000FEA38D5E1" 
$MACAddress[3] = "000FEA38D090" 
$MACAddress[4] = "00016CD6DB40"
$MACAddress[5] = "001A4D74A1D1" 
$MACAddress[6] = "001A4D08C9D6"
$MACAddress[7] = "000FEA38D42F" 
$MACAddress[8] = "000D61468AEB" 
$MACAddress[9] = "000FEAF5EC65"
$MACAddress[10] = "0002E32322E3" 
$MACAddress[11] = "001485F17150" 
$MACAddress[12] = "000D61401AF8"
$MACAddress[13] = "000FEAF1BD96" 


  
    FOR $element IN $MACAddress
            WOL()
            Sleep(1000)
    ;MsgBox(0,"",$element,"")
    Next
    MsgBox(0,"","WOL Completed",10)
    Exit

; ===================================================================
; Functions
; ===================================================================

; Wake up on Lan Function (Open connection and broadcast to Lan)
Func WOL()
UDPStartUp()
$connexion = UDPOpen($Broadcast,7)
UDPSend($connexion, GenerateMagicPacket($element))
UDPCloseSocket($connexion)
UDPShutdown()
EndFunc


; 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

Assumes a broadcast address of 255

Uses an Array

Edited by n2989
Link to comment
Share on other sites

// edit 20.07.2009 -- added TheSovereign get_mac function

// edit 31.03.2010 -- a new version of the WOLLE.AU3 was postet here : >>>WOLLE V2

I found this thread and the starting script.

The script worked not (but not of the main WOL feature, but because it uses only @IpAdress1)

By writing something around the script finally I came to a little bigger script.....

What could the extended script do?

1) You can enter a IP START and and IP STOP address. The script enumerate the last ip segment (sorry but enumerate in all possible addresses does not fit to my need....)

The script will then write a file(MACLIST.DAT) in the format:

[MACLISTE]
192.168.0.1=08000e42faa7
192.168.0.2=0090fb181c18

2) Of course you can edit the file manually and read via button MACLIST.DAT

3) The file will be read on startup and will display the content in a listview

4) Now you can select a single entry and push the button WAKE UP SELECTED

or

5) Send magic packet to all in the listview

6) it will send the magic packet via @IPAddress1 to @IPAddress4, in my PC there are 4 adapters and the mac was on @IPAddress3.....

7) The button SET TIMER to now will set the time controls(combo) (three) to the current time

8) If you activate the timer with the button ACTIVATE TIMER the script will wait until the EXACT (yes, yes, that's not so nice and a possible gap) and will wake up all in the list

9) The status is just for displaying what is going on

So, as parts of this script are from the community, I want to give something back.

I tested this stuff on XP32/SP3 German. Maybe you can tell if this works for you as well.

This is my first contribution to the forum, so please do not punish me for writing wrong coding rules...

In case of errors please correct my script (but at least here it worked fine :-) )

BTW: I will extent my script to run as a service (maybe with srvany...) so I will add a commandline feature like -WAKEUPTIME:060300 -MACLISTFILE:PCLIST.DAT and a logfile (rolling)

If you like I can post it if it is done...

#include <Array.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Dim $aBrowdcast[4]
$aBrowdcast[0]=@IPAddress1
$aBrowdcast[1]=@IPAddress2
$aBrowdcast[2]=@IPAddress3
$aBrowdcast[3]=@IPAddress4
$filemaclist="MACLIST.DAT"

Dim $MACAddressList[1]
$MACAddressList[0] = "08000e42faa7"

; ===================================================================
; Gui
;   
; ===================================================================
$mainwindow=GUICreate("WOLLE",450,300)
$mwbtnExit=GUICtrlCreateButton("Exit",350,150,100)
$mwbtnGetMac=GUICtrlCreateButton("Get Mac adresses",10,150,100)
$mwbtnWakeupall=GUICtrlCreateButton("Wake up all in list",130,150,100)
$mwbtnWakeupSelected=GUICtrlCreateButton("Wake up selected",240,150,100)
$mwlblIpRange=GUICtrlCreateLabel("Enter Start and End IP for search, will only search for last segment, sorry....",10,115,200,30)

$mvinpIpStart=GUICtrlCreateInput("192.168.0.1",250,120,100,15)
$mvinpIpStop=GUICtrlCreateInput("192.168.0.10",350,120,100,15)
$mvinpWakeupTimeHH=GUICtrlCreateCombo("0",10,220,40)
$mvinpWakeupTimeMM=GUICtrlCreateCombo("00",50,220,40)
$mvinpWakeupTimeSS=GUICtrlCreateCombo("00",90,220,40)
FillTimeCombos()
$mwbtnActivateTimer=GUICtrlCreateButton("Activate Timer",290,220,120)
$mwbtnSetTimertoNow=GUICtrlCreateButton("Set Timer to now",160,220,120)
$mwbtnReadMacListFile=GUICtrlCreateButton("MACLIST.DAT",260,50,120)
$mwlvMacadresses=GUICtrlCreateListView("MacAdresses   |IP                ",10,10,250,100)
$mwlblStatus=GUICtrlCreateLabel("Status:",10,180,400)
readmacfile()
setTimertoNow()
$boolTimerActive=0
GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        select 
            case $msg = $GUI_EVENT_CLOSE 
                ExitLoop
            case $msg = $mwbtnExit 
                ExitLoop
            case $msg = $mwbtnWakeupall 
                wol_all()
            case $msg = $mwbtnGetMac 
                getmacinrange()
            case $msg = $mwbtnGetMac 
                getmacinrange()
            case $msg = $mwbtnWakeupSelected 
                wol_selected()              
            case $msg = $mwbtnReadMacListFile 
                readmacfile()
            case $msg = $mwbtnActivateTimer
                if $boolTimerActive=1 Then
                    TimerDisable(0)
                Else
                    TimerDisable(1)
                endif
            case $msg = $mwbtnSetTimertoNow 
                setTimertoNow()


                
            EndSelect   
            if $boolTimerActive=1 Then
                CheckWakeup()
                sleep(100)
            endif
    WEnd
    GUIDelete()
    exit

; ===================================================================
; Function: setTimertoNow
;   sets the thre time controls to the current time 
; ===================================================================
func setTimertoNow()
    guictrlsetdata($mvinpWakeupTimeHH,@HOUR)
    guictrlsetdata($mvinpWakeupTimeMM,@MIN)
    guictrlsetdata($mvinpWakeupTimeSS,@SEC)
EndFunc

; ===================================================================
; Function: TimerDisable
;   Toggle for the Timer button 
; ===================================================================
func TimerDisable($TimerState)
    $boolTimerActive=$TimerState
    if $TimerState = "0" Then
        GUICtrlSetState($mwbtnExit,$GUI_ENABLE)
        GUICtrlSetState($mwbtnGetMac,$GUI_ENABLE)
        GUICtrlSetState($mwbtnWakeupall,$GUI_ENABLE)
        GUICtrlSetState($mwbtnWakeupSelected,$GUI_ENABLE)
        GUICtrlSetState($mvinpIpStart,$GUI_ENABLE)
        GUICtrlSetState($mvinpIpStop,$GUI_ENABLE)
        GUICtrlSetState($mvinpWakeupTimeHH,$GUI_ENABLE)
        GUICtrlSetState($mvinpWakeupTimeMM,$GUI_ENABLE)
        GUICtrlSetState($mvinpWakeupTimeSS,$GUI_ENABLE)
        GUICtrlSetState($mwbtnReadMacListFile,$GUI_ENABLE)
        GUICtrlSetState($mwbtnSetTimertoNow,$GUI_ENABLE)
        GUICtrlSetData($mwbtnActivateTimer," Activate Timer")
        setStatusMsg("Timer deactivated")
        
    Else
        GUICtrlSetState($mwbtnExit,$GUI_DISABLE)
        GUICtrlSetState($mwbtnGetMac,$GUI_DISABLE)
        GUICtrlSetState($mwbtnWakeupall,$GUI_DISABLE)
        GUICtrlSetState($mwbtnWakeupSelected,$GUI_DISABLE)
        GUICtrlSetState($mvinpIpStart,$GUI_DISABLE)
        GUICtrlSetState($mvinpIpStop,$GUI_DISABLE)
        GUICtrlSetState($mvinpWakeupTimeHH,$GUI_DISABLE)
        GUICtrlSetState($mvinpWakeupTimeMM,$GUI_DISABLE)
        GUICtrlSetState($mvinpWakeupTimeSS,$GUI_DISABLE)
        GUICtrlSetState($mwbtnReadMacListFile,$GUI_DISABLE)
        GUICtrlSetState($mwbtnSetTimertoNow,$GUI_DISABLE)       
        
        GUICtrlSetData($mwbtnActivateTimer," De-Activate Timer")

        EndIf
EndFunc


; ===================================================================
; Function: CheckWakeup
; critical only equal time will trigger (needs omething better like a small range)
; ===================================================================
func CheckWakeup()
    
    $strWakeupTime=GUICtrlRead($mvinpWakeupTimeHH)&GUICtrlRead($mvinpWakeupTimeMM)&GUICtrlRead($mvinpWakeupTimess)
    $strNow=@HOUR&@MIN&@SEC
    setStatusMsg("Current time:"&@HOUR&":"&@MIN&":"&@SEC)
    if $strNOW = $strWakeupTime Then
        SoundPlay(@WindowsDir & "\media\tada.wav",0)
        wol_all()
    EndIf
EndFunc 
; ===================================================================
; Function: FillTimeCombos
;          filling the controls with data 
; ===================================================================
func FillTimeCombos()
    for $i=1 to 23 
            GUICtrlSetData($mvinpWakeupTimeHH,$i)
        Next
    for $i=1 to 59
            GUICtrlSetData($mvinpWakeupTimeMM,$i)
            GUICtrlSetData($mvinpWakeupTimeSS,$i)
        Next
    
EndFunc


; ===================================================================
; Function: readmacfile
;           reads mac list in ini format
; ===================================================================
func readmacfile($filemaclist="MACLIST.DAT")
    if FileExists($filemaclist) Then
        $aMaclist=IniReadSection(@scriptdir&"\"&$filemaclist,"MACLISTE")
        _GUICtrlListView_DeleteAllItems($mwlvMacadresses) 
        for $i  = 1 to $aMaclist[0][0] 
                GUICtrlCreateListViewItem(""&$aMaclist[$i][1]&"|"&$aMaclist[$i][0]&"", $mwlvMacadresses)    
            Next
    EndIf
            
    
    EndFunc
; ===================================================================
; Function: getmacinrange
;           simple try to get all mac adresses from a given range (only last segment)
; ===================================================================
func getmacinrange()
    FileDelete(@ScriptDir&"\"&$filemaclist)
    $aIpStart=StringSplit(GUICtrlRead($mvinpIpStart),".")
    $aIpStop=StringSplit(GUICtrlRead($mvinpIpStop),".")
    
    
                for $IpSegD = $aIpStart[4] to $aIpStop[4]
                    get_mac($aIpStart[1]&"."&$aIpStart[2]&"."&$aIpStart[3]&"."&$IpSegD) 
                Next
                readmacfile()

EndFunc

; ===================================================================
; Function: wol_selected
;   sents magic paket to the macadress selected in listviw
; ===================================================================
func wol_selected()
    $aSelectedItems=_GUICtrlListView_GetSelectedIndices($mwlvMacadresses,true)
    if $aSelectedItems[0] > 0 Then
        $macadress=_GUICtrlListView_GetItemText($mwlvMacadresses,$aSelectedItems[1])
        for $adapter in $aBrowdcast 
            wol_adapter($adapter,$macadress)
        Next
        setStatusMsg("is "&$adapter&" awake?")
    EndIf
    
    
endfunc
; ===================================================================
; Function: wol_all
; 
; ===================================================================
func wol_all()
    
    for $adapter in $aBrowdcast 
        wol_adapter_all($adapter)
    Next
    setStatusMsg("All awake?")
    
endfunc
; ===================================================================
; Function: setStatusMsg($msgtext)
;           $msg    --- Message for status text
; ===================================================================
func setStatusMsg($msgtext)
    GUICtrlSetData($mwlblStatus,"Status:"&$msgtext)
endfunc
; ===================================================================
; Function: wol_adapter($adapter,$$macadress)
;           $adapter        --- is the ipadress of the adapter
;          $macadress       --- is the macadress
; ===================================================================

func wol_adapter($adapter,$macadress)
    if $adapter <> "0.0.0.0" Then
        $IPADRESS = StringSplit($adapter,".")
        $Broadcast = $IPADRESS[1] & "." & $IPADRESS[2] & "." & $IPADRESS[3] & "." & "255"

        $String=""
                setStatusMsg("Sent WOL via "&$Broadcast&" for:"&$macadress)
                WOL($Broadcast,$macadress)
    EndIf
    
    EndFunc

; ===================================================================
; Function: wol_adapter($adapter)
;           $adapter        --- is the ipadress of the adapter
; ===================================================================

func wol_adapter_all($adapter)
    if $adapter <> "0.0.0.0" Then
        $IPADRESS = StringSplit($adapter,".")
        $Broadcast = $IPADRESS[1] & "." & $IPADRESS[2] & "." & $IPADRESS[3] & "." & "255"

        $String=""
      
        FOR $macadress IN $MACAddressList
                setStatusMsg("Sent WOL via "&$Broadcast&" for:"&$macadress)
                WOL($Broadcast,$macadress)
                Sleep(1000)
        Next
    EndIf
    
    EndFunc

; ===================================================================
; Function: WOL($Broadcast,$element)
;          $Broadcast       --- is ipadress of adapter with 255 at the End
;           $MACAddress     --- is the macadress 
; ===================================================================

; Wake up on Lan Function (Open connection and broadcast to Lan)
Func WOL($Broadcast,$MACAddress)
UDPStartUp()
$connexion = UDPOpen($Broadcast,7)
UDPSend($connexion, GenerateMagicPacket($MACAddress))
UDPCloseSocket($connexion)
UDPShutdown()
EndFunc


; 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

; ===================================================================
; Function: get_mac($remote_ip,$filemaclist)
;           $remote_ip      --- remote ip
;           $filemaclist    --- file in ini format
; enhanced by TheSovereign - skip local mac adress
; ===================================================================
func get_mac($remote_ip,$filemaclist="MACLIST.DAT")
                    Ping($remote_ip,200)
                    if @error =0 Then
                        $arpinfo = Run(@ComSpec & " /c ARP -a "&$remote_ip, @SystemDir, @SW_HIDE, 2)
                        sleep(200)
                        $output = StdoutRead($arpinfo, -1)
                            $aOutputLine=StringSplit($output,@CRLF)
                            If UBound($aOutputLine) > 5 Then ; <=== added so script doesn't choke when processing the IP for the computer it's running on
                                $macadress=Stringmid($aOutputLine[7],25,17)
                                $macadress=StringReplace($macadress,"-","")
                                IniWrite(@ScriptDir&"\"&$filemaclist,"MACLISTE",$remote_ip,$macadress)
                                setStatusMsg("Found maclist "&$macadress)
                            EndIf ; <=== and this one...

                        Else
                            setStatusMsg("Host "&$remote_ip&" not reachable")
                            Return
                        endif
                    EndFunc
Edited by Tankbuster
Link to comment
Share on other sites

For those having troubles

Microsoft* Windows Products

Microsoft Windows NT* and Windows* 95 are not ACPI capable. Some settings will not be available in these operating systems. See also the "Other operating systems" section below.

Microsoft Windows 98, Windows Me, Windows 2000, Windows XP, Windows Vista are ACPI capable. These operating systems do not support wake from S5 state, only from standby. However, in some ACPI capable computers, the BIOS may have a setting that allows you to wake from an S5 state anyway. If there is no support for wake from S5 state in your BIOS settings, then you will be limited to wake from standby when utilizing these operating systems in ACPI computers.

In the adapters advanced settings, there is a setting titled "Enable PME." To explicitly allow wake up with a Magic Packet from shutdown under APM power management mode, set this to "Enable."

In ACPI capable versions of Windows, there will also be a setting titled "Wake on Settings." This controls the type of packets that will wake up the system from standby. Click the Help button in PROSet for a complete explanation.

In ACPI computers running ACPI aware operating systems such as Windows* XP, in Device Manager, the adapter properties will display a tab titled "Power Management." The setting "allow this device to bring the computer out of standby" should be checked.

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

  • 4 weeks later...

this works great!

except ive noticed like with other wake on lan clients...

it only works every other time

in other words..

1. i shut down pc

2. wake it up - and it works!

3. shut down pc again

4. wake it up - fails

5. turn on pc manually

6. wake it up - and it works!

..

..

..

ive had the same result on multiple pcs..

any idea?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...