pastebin - collaborative debugging tool
kpaste.net RSS


Send-WakeOnLANpacket
Posted by Anonymous on Fri 29th Sep 2017 15:53
raw | new post

  1. function Send-WOL
  2. {
  3. <#
  4.   .SYNOPSIS  
  5.     Send a WOL packet to a broadcast address
  6.   .PARAMETER mac
  7.    The MAC address of the device that need to wake up
  8.   .PARAMETER ip
  9.    The IP address where the WOL packet will be sent to
  10.   .EXAMPLE
  11.    Send-WOL -mac 00:11:32:21:2D:11 -ip 192.168.8.255
  12. #>
  13.  
  14. [CmdletBinding()]
  15. param(
  16. [Parameter(Mandatory=$True,Position=1)]
  17. [string]$mac,
  18. [string]$ip="255.255.255.255",
  19. [int]$port=9
  20. )
  21. $broadcast = [Net.IPAddress]::Parse($ip)
  22.  
  23. $mac=(($mac.replace(":","")).replace("-","")).replace(".","")
  24. $target=0,2,4,6,8,10 | % {[convert]::ToByte($mac.substring($_,2),16)}
  25. $packet = (,[byte]255 * 6) + ($target * 16)
  26.  
  27. $UDPclient = new-Object System.Net.Sockets.UdpClient
  28. $UDPclient.Connect($broadcast,$port)
  29. [void]$UDPclient.Send($packet, 102)
  30.  
  31. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at