Titus
Titus

Reputation: 512

send magic packet from windows with one click

WOL works perfectly well via the Router, but that requires logging in to the control and browse trought the menus. I want to wake up the machine with one (double) click.

I tried

Both throw Syntax Errors, wether I try them with cmd or the PowerShell.

Bash one-line command to send wake on LAN magic packet without specific tool probably works in linux, but definitely not on windows

Is there a one-liner for Windows or anything that I can put in a bash batch file that actually works?


edit:

I got the second script to run (rename to .ps1, changed execution policy in PowerShell), but not to work.

Tried https://www.itnator.net/wake-lan-script-wol/ but this throws an exception:

Send-Packet : Ausnahme beim Aufrufen von "Parse" mit 1 Argument(en):  "Die angegebene physikalische Adresse ist
ungültig."
In C:\wol-script.ps1:38 Zeichen:1
+ Send-Packet <mac-address>
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-Packet

Fehler beim Durchlaufen einer Auflistung: Die Sammlung wurde geändert. Der Enumerationsvorgang kann möglicherweise
nicht ausgeführt werden..
In C:\wol-script.ps1:29 Zeichen:3
+         $Error | Write-Error;
+         ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Collecti...numeratorSimple:ArrayListEnumeratorSimple) [], Runt
   imeException
    + FullyQualifiedErrorId : BadEnumeration

Upvotes: 1

Views: 15796

Answers (2)

timbck2
timbck2

Reputation: 1066

I found a simple Powershell script on another question/answer site that works. I made some minor changes (added comment block explaining how to use it, added parameters so the necessary info can be provided up front).

Here it is:

<#
    Send-WOL.ps1
    Sends "magic" Wake on LAN packet to attempt to wake the target computer
    It is necessary to specify another computer on the same subnet as the target since the packet
    is only broadcast to the subnet the target is on
    Parameters: Target (required) : MAC address of target (xx:xx:xx:xx:xx:xx)
                RemoteIP (required): IP address of another computer on the same subnet as target
#>

# Setup params
Param(
    [Parameter(Mandatory=$true)][String]$Target,
    [Parameter(Mandatory=$true)][String]$RemoteIP
)

Write-Verbose -Message "Converting MAC address $($Target) to a byte array" -Verbose
$MacByteArray = $Target -split "[:-]" | ForEach-Object { [Byte] "0x$_"}
[Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray * 16)
Write-Verbose -Message "Broadcasting Wake-on-LAN packet to target." -Verbose
Invoke-Command -ComputerName $RemoteIP -ScriptBlock {
    $UdpClient = New-Object System.Net.Sockets.UdpClient
    $UdpClient.Connect(([System.Net.IPAddress]::Broadcast),7)
    $UdpClient.Send($using:MagicPacket,$using:MagicPacket.Length)
    $UdpClient.Close()
}

Upvotes: 1

Titus
Titus

Reputation: 512

https://www.gammadyne.com/cmdline.htm#wol works, and it´s "only" 193K (go-wol is around 5MB).
I will put a batch script around it and then I´m done.
A deep link into the router setup would be smaller, but I guess that the AVM software does not allow that.

Only wish remaining is to hibernate the machine via Magic Packet, but my NIC is probably too old for that. I think I will use PuTTY for that.

Thanks everyone for digging!

Upvotes: 1

Related Questions