From e33c72470d3ab95098b56166d428d66f1e212ac7 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 8 May 2023 09:14:55 +0200 Subject: [PATCH] Update wake-up.ps1 --- Scripts/wake-up.ps1 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Scripts/wake-up.ps1 b/Scripts/wake-up.ps1 index 319168f9..64f5042c 100755 --- a/Scripts/wake-up.ps1 +++ b/Scripts/wake-up.ps1 @@ -6,9 +6,11 @@ .PARAMETER MACaddress Specifies the host's MAC address (e.g. 11:22:33:44:55:66) .PARAMETER IPaddress - Specifies the host's IP address or subnet address (e.g. 255.255.255.255) + Specifies the host's IP address or subnet address (e.g. 192.168.0.255) .PARAMETER Port Specifies the UDP port (9 by default) +.PARAMETER NumRetries + Specifies number of retries (3 by default) .EXAMPLE PS> ./wake-up.ps1 11:22:33:44:55:66 192.168.100.100 .LINK @@ -17,7 +19,7 @@ Author: Markus Fleschutz | License: CC0 #> -param([string]$MACaddress = "", [string]$IPaddress = "", [int]$Port=9) +param([string]$MACaddress = "", [string]$IPaddress = "", [int]$Port=9, [int]$NumRetries=3) function Send-WOL { param([string]$mac, [string]$ip, [int]$port) $broadcast = [Net.IPAddress]::Parse($ip) @@ -32,14 +34,15 @@ function Send-WOL { param([string]$mac, [string]$ip, [int]$port) } try { - if ($MACaddress -eq "" ) { $MACaddress = Read-Host "Enter the host's MAC address (e.g. 00:11:22:33:44:55)" } - if ($IPaddress -eq "" ) { $IPaddress = Read-Host "Enter the host's IP address or subnet address (e.g. 255.255.255.255)" } + if ($MACaddress -eq "" ) { $MACaddress = Read-Host "Enter the host's MAC address (e.g. 11:22:33:44:55:66)" } + if ($IPaddress -eq "" ) { $IPaddress = Read-Host "Enter the host's IP address or subnet address (e.g. 192.168.0.255)" } Send-WOL $MACaddress $IPaddress $Port - Start-Sleep -milliseconds 100 - Send-WOL $MACaddress $IPaddress $Port - - "✔️ sent magic packet $MACaddress to IP $IPaddress on port $Port (twice)" + for ($i = 0; $i -lt $NumRetries; $i++) { + Start-Sleep -milliseconds 100 + Send-WOL $MACaddress $IPaddress $Port + } + "✔️ sent magic packet $MACaddress to IP $IPaddress on port $Port ($NumRetries retries)" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"