Giter Site home page Giter Site logo

wakeonlan's Introduction

Invoke-WakeOnLan

Chris Warwick, @cjwarwickps, November 2015

Cmdlet to send a Wake-on-Lan packet to a specified target MAC addresses.

Wake on Lan (WOL) uses a "Magic Packet" that consists of six bytes of 0xFF (the physical layer broadcast address), followed by 16 copies of the 6-byte (48-bit) target MAC address (see http://en.wikipedia.org/wiki/Wake-on-LAN).

This packet is sent via UDP to the LAN Broadcast addresses (255.255.255.255) on arbitrary Port 4000.

Construction of this packet in PowerShell is very straight-forward: ("$Packet = Byte[]+($Mac*16)").

This script has a (hard-coded) table of saved MAC addresses to allow machine aliases to be specified as parameters to the function (the real addresses have been obfuscated here) and uses a regex to validate MAC address strings.

It would be possible to use DNS and the ARP Cache to resolve MAC addresses, however, the ARP cache will only be populated with a valid entry for any given target adapter for a relative short period of time after the last use of the address (10 minutes or less depending on usage); ARP cannot be used to dynamically resolve the address of a suspended adapter.

Script Help


<#
.Synopsis
    This cmdlet sends Wake-on-Lan Magic Packets to the specified Mac addresses.
.Description
    Wake on Lan (WOL) uses a "Magic Packet" that consists of six bytes of 0xFF (the physical layer broadcast address), followed 
    by 16 copies of the 6-byte (48-bit) target MAC address (see http://en.wikipedia.org/wiki/Wake-on-LAN).   

    This packet is sent via UDP to the LAN Broadcast addresses (255.255.255.255) on arbitrary Port 4000.  

    Construction of this packet in PowerShell is very straight-forward: ("$Packet = [Byte[]](,0xFF*6)+($Mac*16)").

    This script has a (hard-coded) table of saved MAC addresses to allow machine aliases to be specified as parameters to the 
    function (the real addresses have been obfuscated here) and uses a regex to validate MAC address strings.  The address
    aliases are contained in a hash table in the script - but they could very easily be obtained from an external source such as 
    a text file or a CSV file (this is left as an exercise for the reader).

    It would be possible to use DNS and the ARP Cache to resolve MAC addresses, however, the ARP cache will only be populated with
    a valid entry for any given target adapter for a relative short period of time after the last use of the address (10 minutes 
    or less depending on usage); ARP cannot be used to dynamically resolve the address of a suspended adapter.
.Example
    Invoke-WakeOnLan 00-1F-D0-98-CD-44
    Sends WOL packets to the specified address
.Example
    Invoke-WakeOnLan 00-1F-D0-98-CD-44, 00-1D-92-3B-C2-C8
    Sends WOL packets to the specified addresses
.Example
    00-1F-D0-98-CD-44, 00-1D-92-3B-C2-C8 | Invoke-WakeOnLan
    Sends WOL packets to the specified addresses
.Example
    Invoke-WakeOnLan Server3
    Sends WOL packets to the specified target using an alias.  The alias must currently be hard-coded in the script.
.Inputs
    An array of MAC addresses.  Each address must be specified as a sequence of 6 hex-coded bytes seperated by ':' or '-'
    The input can also contain aliases - these must currently be hard-coded in the script (see examples)
    MAC addresses can be piped to the cmdlet.
.Outputs
    Wake-on-Lan packets are sent to the specified addresses
.Parameter MacAddress
    An array of MAC addresses.  Each address must be specified as a sequence of 6 hex-coded bytes seperated by ':' or '-'
.Functionality
    Sends Wake-on-Lan Magic Packets to the specified Mac addresses
#>


Version History:

V1.0 (This Version)

  • Initial release to the PowerShell Gallery

V0.1-0.9 Dev versions

Other Modules:

See all my other PS Gallery modules:

  Find-Module | Where Author -match 'Chris Warwick'

wakeonlan's People

Contributors

chriswarwick avatar detlefs avatar

Stargazers

Spiral Chaotic avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.