Jump to content

Copyright-free Wake on LAN script !


Olish
 Share

Recommended Posts

This doe`nt work for me, I know the Mac and IP addy are correct as this Utility http://www.tnk-bootblock.co.uk/software/in...amp;id=5D3C17E4 turns on the PC.

Broadcast Address on this is set to 255.255.255.255 as Default, So, do I need to specify a broadcast addy as well as the Mac and IP?

Is there a way to use this to turn Off a PC, rather than having to use remote desktop and do it from the taskmanager?

Thanks.

Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Broadcast Address on this is set to 255.255.255.255 as Default, So, do I need to specify a broadcast addy as well as the Mac and IP?

wrong IP addr. Read the code in the first post. It uses the network broadcast address not 255.255.255.255. I believe the UDP functions don't work with the general broadcast.

Is there a way to use this to turn Off a PC, rather than having to use remote desktop and do it from the taskmanager?

well this is called WAKE on Lan, so no "go to sleep"!

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

wrong IP addr. Read the code in the first post. It uses the network broadcast address not 255.255.255.255. I believe the UDP functions don't work with the general broadcast.

well this is called WAKE on Lan, so no "go to sleep"!

Cheers

Kurt

LOL! on the "go to sleep"!

There is some confusion on the terminology used here, in the autoit app the broadcast address is the IP address of the remote computer, in the Wake onLan.Ex utility the Broadcast address is a Network Mask.

So, the Wake On Lan.ex utility works, but if I put exactly the same IP and MAC details into this script, nothing happens, the only thing different is the network mask entry, I don`t know what its for or what it does?

Here`s my details at the start of the script:

$IPAddress = "192.168.0.10"; This is the broadcast address !
$MACAddress = "000E2E8CD948"
Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Hmm... Well how exactly does this turn on a PC? Does it actually tell the PC that the power button was pressed and that it should boot up? I couldn't possibly work, because I have to turn on a Power Strip (6 socket bar plugged into wall outlet) then press the power button to turn the computer on. I don't get exactly what this script is trying to do???

- Dan [Website]

Link to comment
Share on other sites

$IPAddress = "192.168.0.10"; This is the broadcast address !

no, that's not the broadcast address! What's your IP addr and netmask of

the PC you are running the script on?

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

I don't understand the purpose of this script either, would someone like to elaborate on the use of it?

google "wake on lan"!

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

no, that's not the broadcast address! What's your IP addr and netmask of

the PC you are running the script on?

Cheers

Kurt

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Realtek RTL8169/8110 Family Gigab

Ethernet NIC

Physical Address. . . . . . . . . : 00-0E-2E-8C-D7-5B

Dhcp Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.0.1

Subnet Mask . . . . . . . . . . . : 255.255.255.0

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Realtek RTL8169/8110 Family Gigab

Ethernet NIC

Physical Address. . . . . . . . . : 00-0E-2E-8C-D7-5B

Dhcp Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.0.1

Subnet Mask . . . . . . . . . . . : 255.255.255.0

then your bcast addr is 192.168.0.255.

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

I decided to post some explanation, even thou this is not my topic and everyone can use Wikipedia.

How it works

The target computer is shut down, with power reserved for the network card. The network card listens for a specific packet, called the Magic Packet. The Magic Packet is broadcast on the broadcast address for that particular subnet or the entire LAN. The listening computer receives this packet, checks it for the correct information, and then boots if the Magic Packet is valid.

What is Magic Packet

The Magic Packet is a broadcast frame, transmitted over port 7 or 9. It can be sent over a variety of connectionless protocols (UDP, IPX) but UDP is most commonly used. The data that is contained in a Magic Packet is the defined constant as represented in hexadecimal: FF FF FF FF FF FF followed by sixteen repetitions of the target computer's MAC address, possibly followed by a four or six byte password.

What is Broadcasting Adress

In computer networking, a broadcast address is an IP address that allows information to be sent to all machines on a given subnet rather than a specific machine. The exact notation can vary by operating system, but the standard is laid out in RFC 919.

In other words when you send a packet to specic IP called broadcast adress that IP resends your message to all ips in it's range. If your computer's ethernet card is active and waiting for such message it starts up your computer. It's that simple ;)

Wake on Lan is diffrent thing then Wake on Ring. As stated above Wake on Ring is for Modems and Wake on Lan for Ethernet Cards. New motherboards have Wake On Lan implemented so if you got no Wake on Lan in BIOS you can just replace your motherboard with new one :P

If you want to get MAC adress of some computer in your network. You can simply go to Start -> Run -> Type in "cmd". And in that window type "ping 192.168.0.1 (or other ip adress of your choice)" and then type "arp -a". That list should give you MAC adress for IP.

Thank You and good luck :whistle:

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

I decided to post some explanation, even thou this is not my topic and everyone can use Wikipedia.

What is Broadcasting Adress

In computer networking, a broadcast address is an IP address that allows information to be sent to all machines on a given subnet rather than a specific machine. The exact notation can vary by operating system, but the standard is laid out in RFC 919.

In other words when you send a packet to specic IP called broadcast adress that IP resends your message to all ips in it's range. If your computer's ethernet card is active and waiting for such message it starts up your computer. It's that simple ;)

Thank You and good luck :whistle:

Thanks for explaination!

So, would the broadcast address 192.168.0.255 start all machines in the range from 192.168.0.1 to 192.168.0.255, or would it only start the machine with the mac address of a particular PC?

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Thanks for explaination!

So, would the broadcast address 192.168.0.255 start all machines in the range from 192.168.0.1 to 192.168.0.255, or would it only start the machine with the mac address of a particular PC?

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

$MACAddress = "020000D00406"
UDPStartUp()
$connexion = UDPOpen($Broadcast,7)
UDPSend($connexion, GenerateMagicPacket($MACAddress))
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

This will auto generate the broadcast address and wake up the PC with MAC = 020000D00406

Regards

Trolderik

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

This will auto generate the broadcast address and wake up the PC with MAC = 020000D00406

Regards

Trolderik

That code wont always bring the broadcast adress. It's just a coincidence that the broadcast sometimes ends on 255.

A bit of knowledge:

IP addresses have classes (A, B, C and, also, D)

Every IP is on a net and sometimes on a subnet (there comes the subnet mask -SM-).

So you can have the IP 192.168.0.2 (...0.1 is the router on this example net) and a SM of 255.255.255.64 wich means that on this subnet can only be 62 different addresses, a net address (the lowest number 192.168.0.0) and a broadcast adress (wich is always the highest number: 192.168.0.63).

You can also have the IP 192.168.0.90 and the same SM so your broadcast will be 192.168.0.127 and the net address, 192.168.0.64 but you can't communicate directly with 192.168.0.2 because that is on the other subnet and there is where the router does it's job: if the IP is on the same subnet it lets the packets move inside the net, else, it sends the packet right out of the subnet to the other router.

@Klaatu: I think that you are wrong when you say that, as you have a Class A address range, then your SM has to be 255.255.255.255. Also, no WOL program needs an IP address to work as computers that are off don't have IP address. In this script you need to know the broadcast IP address. (post #23)

I'll be working on a work around to automatically get the broadcast.

It is just some math with the IP and de SM.

Also I will be working on a script that gets all the MACs on a net and stores them into a list with their IPs (maybe also the PC name) so I can just select wich machine(s) wake, all from the same script.

on wich port is the programming broadcasting? because I'm looking for a way to startup my desktop at home true the internet.

But than I have to open a port on my router. So I need to now witch port

I don't think that WOL should work on nets outside the one you are in. Anyway, Madboy says on the post#53 that the ports are 7 or 9 although that, for me, it works on any port from 1 to 65535. This link has more info but it doesn't mention ports anyway: http://gsd.di.uminho.pt/jpo/software/wakeo...ni-howto-2.html. I don't think there is a port for this kind of packets.

But an idea has came to me right now: instead of opening a port, translate it and redirect it to the broadcast address of the net in wich your router is. This can be called virtual server (D-Link), NAT, network address translation or whatever the manufacturer has chosen :-(.

Example: set your router to listen on the port 32154 and redirect what is received to the same port, or any other, on the IP 192.168.0.255. I dont know wich security issues this can have (everything on the internet talking to this port will be listened by all the computers in your net). So I advice to enable this port just when you need to wake your PC and then disable it. I take no responsability on what can happen! Just be careful and use a rare (high) number of port.

I configured it right now and will be testing it next monday from the office. I hope it works so I don't have to leave my computer on every day just in case I need to get something at home.

I will post the results.

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

  • 3 weeks later...

Hi all. Just thought I would help out a little here. In case you are having trouble figuring out your broadcast address, I made it so Olish's script will automagically figure out your Broadcast IP of the network you are on and use it. This is more accurate than Trolderik's script, as it is how you are actually supposed to figure out the broadcast address (see ktulu789's post above mine). I also added an inputbox for the MAC address. Oooh spiffy. :whistle:

#include <process.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, ".")
If $arrSubnetMask[1] = 255 Then
    $strBroadcastIP = $arrIPAddress[1]
Else
    $strBroadcastIP = 255 - $arrSubnetMask[1]
EndIf
For $i = 2 to 4
    If $arrSubnetMask[$i] = 255 Then
        $strBroadcastIP = $strBroadcastIP & "." & $arrIPAddress[$i]
    Else
        $strBroadcastIP = $strBroadcastIP & "." & 255 - $arrSubnetMask[$i]
    EndIf
Next

$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
    
EndFunc
Edited by ReverendJ1
Link to comment
Share on other sites

Hi all. Just thought I would help out a little here. In case you are having trouble figuring out your broadcast address, I made it so Olish's script will automagically figure out your Broadcast IP of the network you are on and use it. This is more accurate than Trolderik's script, as it is how you are actually supposed to figure out the broadcast address (see ktulu789's post above mine). I also added an inputbox for the MAC address. Oooh spiffy. :whistle:

Hi, you script does not work for a Subnet mask of 255.255.255.248. You should rethink your broadcast calculation algorithm...

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

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