Last active
August 29, 2015 14:18
-
-
Save tibmeister/98c0db7142153afa1f32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Send a WOL packet to a broadcast address | |
.PARAMETER mac | |
The MAC address of the device that need to wake up | |
.PARAMETER ip | |
The IP address where the WOL packet will be sent to | |
.EXAMPLE | |
Send-WOL -mac 00:11:32:21:2D:11 -ip 192.168.8.255 | |
#> | |
param( | |
[string]$mac, | |
[string]$ip, | |
[int]$port=9 | |
) | |
$broadcast = [Net.IPAddress]::Parse($ip) | |
$mac=(($mac.replace(":","")).replace("-","")).replace(".","") | |
$target=0,2,4,6,8,10 | % {[convert]::ToByte($mac.substring($_,2),16)} | |
$packet = (,[byte]255 * 6) + ($target * 16) | |
$UDPclient = new-Object System.Net.Sockets.UdpClient | |
$UDPclient.Connect($broadcast,$port) | |
[void]$UDPclient.Send($packet, 102) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment