Jump to content

Copyright-free Wake on LAN script !


Olish
 Share

Recommended Posts

Is it also possible to wake up 1 pc instead of all in your subnet?

Some Wake On Lan tools you can enter the mac adress of the pc and that one and only that one will boot up.

That's what this does...

it only wakes up the pc with the IP address and MAC address you specify...

Link to comment
Share on other sites

I'd like to turn this into a function, i.e.,

Func WOL($MACAddress, $IPAddress = "255.255.255.255")
   UDPStartup()

   Local $connexion = UDPOpen($IPAddress, 7)
   Local $res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
   ; MsgBox(0, "", $res)
   UDPCloseSocket($connexion)
   UDPShutdown()
EndFunc

I've not read if it's safe to use UDPStartup() and UDPShutdown() within a function like this. Would it screw up any other UDP that may be happening in other places in the script? If so, how can I tell if UDPStartup() has been called previous to the function so I can avoid screwing stuff up outside of the function?

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

Also, I've tried this and I can't get it to work anyway. I understand that the $IPAddress parameter is a broadcast address, not a specific computer IP address, so the 255 basically says to broadcast to all with any number in that position. I'm on a Class A private network. Everything within the office starts with "10.64", with DHCP handing out IP addresses to workstations using "192" as the third number. I've tried using "255.255.255.255" as the IP address to wake up a computer (which does respond using a different WOL utility), but that didn't work. But I've also tried "10.255.255.255", "10.64.255.255", and "10.64.192.255" too, and none of those worked either.

Any idea what I'm doing worng?

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

Also, I've tried this and I can't get it to work anyway. I understand that the $IPAddress parameter is a broadcast address, not a specific computer IP address, so the 255 basically says to broadcast to all with any number in that position. I'm on a Class A private network. Everything within the office starts with "10.64", with DHCP handing out IP addresses to workstations using "192" as the third number. I've tried using "255.255.255.255" as the IP address to wake up a computer (which does respond using a different WOL utility), but that didn't work. But I've also tried "10.255.255.255", "10.64.255.255", and "10.64.192.255" too, and none of those worked either.

Any idea what I'm doing worng?

Not a broadcast. Specify the IP address of the comptuer you are targeting, AND the MAC address of the comptuer you are targeting.

The only reason for the MAC address is because the Magic packet information is generated from the MAC address.

At least this is what I gather from looking at the script.

Mike

Link to comment
Share on other sites

But a turned off computer doesn't have an IP address...

Right?

Right, but the switch that it's attached to remember the last IP assigned to what port, so it will automatically attempt to forward information for a specific IP to the last port that had it. Also, because the computers that have WOL capabilities still give power to the NIC even if the PC is off the switch still sees the computer as on.

I may be confusing what the Switch does with what the Server does...

Mike

Link to comment
Share on other sites

This does the exact same thing:

; Target PC Info
$IP = "192.168.1.255"
$MAC = "000D8787E226"

UDPStartUp()
$sock = UDPOpen($IP, 7)
UDPSend($sock, BinaryString('0xFFFFFFFFFFFF' & _Repeat($MAC, 16)))
UDPCloseSocket($sock)
UDPShutdown()

Func _Repeat( $str, $reps )
   Local $ret = ''
   For $i = 1 to $reps
      $ret &= $str
   Next
   Return $ret
EndFunc
:whistle: Edited by erifash
Link to comment
Share on other sites

This does the exact same thing:

Strange. Why do I get an 'Error: Unknown function name' when my script reaches the BinaryString function? I know I'm using the beta (3.1.1.129 to be exact).
My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

Strange. Why do I get an 'Error: Unknown function name' when my script reaches the BinaryString function? I know I'm using the beta (3.1.1.129 to be exact).

sure? Script works fine...

msgbox(4096,"Version",@AutoItVersion)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Also, I've tried this and I can't get it to work anyway.

I know some people mentioned that you have to have the correct BIOS setting. I also know that the WOL functionality can be turned on and off in the network card (switches and/or software tool).
Link to comment
Share on other sites

sure? Script works fine...

msgbox(4096,"Version",@AutoItVersion)

D'oh! Yep, I was calling the wrong version of AutoIt.

I know some people mentioned that you have to have the correct BIOS setting. I also know that the WOL functionality can be turned on and off in the network card (switches and/or software tool).

Yes, I'm very familiar with the BIOS settings that are needed. And I did mention that I can get the computer to wake up using a different WOL utility, so the BIOS settings are correct. All I can think of is it's somehow related to the IP address I'm sending out on the network, but I've tried about everything I can think of. I've tried every combination from the specific IP address of the turned off machine to 255.255.255.255; nothing is working. It's probably something real simple I'm doing wrong, as others say they've got this code to succeed, but I'm at a loss right now.

Although, now that I think about it, like the problem above, maybe it's also related to calling a non-beta version of AutoIt! I've got the beta installed, but I could be specifying the path directly instead of letting things default, which might cause it.

Nope, just tested it, leaving the 'MsgBox(4096,"Version",@AutoItVersion)' code in, and it's definately beta 129 that I'm using (now anyway) and the computer still is not waking. Damn, and I really want this to work, too.

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

D'oh! Yep, I was calling the wrong version of AutoIt.

Yes, I'm very familiar with the BIOS settings that are needed. And I did mention that I can get the computer to wake up using a different WOL utility, so the BIOS settings are correct. All I can think of is it's somehow related to the IP address I'm sending out on the network, but I've tried about everything I can think of. I've tried every combination from the specific IP address of the turned off machine to 255.255.255.255; nothing is working. It's probably something real simple I'm doing wrong, as others say they've got this code to succeed, but I'm at a loss right now.

Two things:

1.) Did you use the correct MAC addr. of the computer you want to wake? Really sure???

2.) You'll have to use the local network broadcast address (x.x.x.255 if your sending computer uses a class C network mask)!!! Otherwise your system will try to resolve the IP address to a mac address (needed to send the packet on the ethernet). This will not work, as there is nobody to answer the ARP Request packet (Remeber: The one that has that IP and MAC address is sleeping) ;-)) If you're using DHCP it's even worse. A completely unrelated system will answer the ARP request with it's own MAC address if that IP address was given to it.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Also, make sure you are typing the MAC address in all CAPS, and I'm sure you know there there are no spaces, Dashes, or anything else in the MAC.

Yes, it's all caps alright, and there are no other characters there. The MAC I'm using is "000D603BE832", which I'm sure is the MAC address of the machine I'm trying to wake, as the other WOL utility wakes the machine fine when I specify this same MAC (although it wants colons between the bytes).

One thing I noticed in checking the return value from the UDPSend() function was that I was getting a return value of -1 when the IP Address I was specifying (to the UDPOpen() function) was "255.255.255.255". The documentation for the UDPSend() function specifies that it returns 0 on error, not -1, so not sure why I'm getting -1 returned. Assuming the documentation is partly wrong for a second, when I get -1 returned from UDPSend(), @Error is set to 1, possibly indicating that the IP Address parameter is incorrect. But from what I understand, "255.255.255.255" should be a valid IP address to use with UDPOpen(), and in fact UDPOpen() does return success when using this address. So I'm not sure why UDPSend() is failing when "255.255.255.255" was used in the call to UDPOpen(). From what I can tell, the other WOL utility I use sends its magic packet to this IP address, so I'm trying to duplicate what it sends since sending the packet to "10.64.192.144", "10.64.192.255", "10.64.255.255", and "10.255.255.255" all do not work for me, but do indicate a successful return from UDPSend().

Edited by Klaatu
My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

1.) Did you use the correct MAC addr. of the computer you want to wake? Really sure???

How much more sure can I be when

E:\Admin>wol -p=7 00:0D:60:3B:E8:32
wol: packet sent to 0007:FFFFFFFF-00:0D:60:3B:E8:32

wakes up the computer and

Local $IP, $MAC, $sock, $ret
$IP = "255.255.255.255"
$MAC = "000D603BE832"

UDPStartUp()
$sock = UDPOpen($IP, 7)
If IsArray($sock) Then MsgBox(4096,"UDPOpen", $sock[1] & " " & $sock[2] & " " & $sock[3])
$ret = UDPSend($sock, BinaryString('0xFFFFFFFFFFFF' & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC & $MAC))
If $ret <> 102 then MsgBox(4096,"UPDSend",$ret & " " & @Error)
UDPCloseSocket($sock)
UDPShutdown()

does not?

2.) You'll have to use the local network broadcast address (x.x.x.255 if your sending computer uses a class C network mask)!!! Otherwise your system will try to resolve the IP address to a mac address (needed to send the packet on the ethernet). This will not work, as there is nobody to answer the ARP Request packet (Remeber: The one that has that IP and MAC address is sleeping) ;-)) If you're using DHCP it's even worse. A completely unrelated system will answer the ARP request with it's own MAC address if that IP address was given to it.

It's actually a Class A private network, but as I said I've tried everything from the specific IP address of the computer, and all broadcast addresses from x.x.x.255 all the way to 255.255.255.255 without success. Only the last (255.255.255.255) apparently gives an error returned from UDPSend().
My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

Local $IP, $MAC, $sock, $ret
$IP = "255.255.255.255"

does not?

IP address is wrong.

It's actually a Class A private network, but as I said I've tried everything from the specific IP address of the computer, and all broadcast addresses from x.x.x.255 all the way to 255.255.255.255 without success. Only the last (255.255.255.255) apparently gives an error returned from UDPSend().

1.) what is the IP address of the sender and the netmask (probably send output of ipconfig)?

2.) Install wireshark sniffer and check what your computer sends if you use WOL and the AutoIT script. However, you must specify the correct IP address in your script (broadcast IP addr. of your network segment). If you use the broadcast IP, the packet should be sent to mac. addr: FF:FF:FF:FF:FF:FF !! That's important, see my other post about ARP.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • 1 month later...

:) great ive been looking for something like this... prolly wouldnt be to hard to add a gui asking for ip addy each time or maybe sending to multiple ips? also add a sleep on LAN function (shutdown computer)? That would be great!

mostly just thinkin out loud...

Edited by jzn2
Link to comment
Share on other sites

Stupid question time! :):P

Where do I look for the MAC address of a PC?

Thanks!

This should work I believe:

Func _IP2MAC( $sIP )
    Local $oWMI = ObjGet("winmgmts:\\" & $sIP & "\root\CIMV2")
    If @error Then Return SetError(1, @error, "")
    Local $oNet = $oWMI.ExecQuery("SELECT IPAddress,MACAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", 48)
    If @error Then Return SetError(2, @error, "")
    For $o In $oNet
        If $o.IPAddress(0) = $sIP Then Return StringReplace($o.MACAddress, ":", "")
    Next
    Return SetError(3, @error, "")
EndFunc

Based on code from Scriptomatic by SvenP.

Edited by erifash
Link to comment
Share on other sites

  • 2 weeks later...

This is working only for the local computer (it gives no results for other IPs on the subnet, even it they are open). However I may have miss something because my terminals are quite tuned up (maybe I have disabled a service on them).

I also thinks that it has the disadvantage that the remote computer must be open, and also that it must use Windows.

However the old command line's 'arp -a IP' would do the trick relying on no additional services and OSes. If somebody can extract the MAC address part out of this (maybe with ConsoleRead?), it would be a great addition to the script.

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...