Last active
February 26, 2020 14:06
-
-
Save mono0x/35b3ce1f23d4bbd10b09c5de6a9d487d 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
$ErrorActionPreference = "Stop" | |
$macAddresses = @($Args | ForEach-Object { $_.Replace(":", "-") }) | |
$header = [byte[]](@(0xFF) * 6) | |
foreach ($macAddress in $macAddresses) { | |
$payload = [byte[]]($macAddress.split("-") | ForEach-Object { [Convert]::ToInt32($_, 16) }) | |
$magicPacket = $header + $payload * 16 | |
$client = New-Object System.Net.Sockets.UdpClient | |
try { | |
$client.Connect([System.Net.IPAddress]::Broadcast, 2304) | |
$client.Send($magicPacket, $magicPacket.Length) | Out-Null | |
} | |
finally { | |
$client.Close() | |
} | |
} | |
if ($macAddresses.Count -ne 0) { | |
$ipAddresses = Get-NetNeighbor -AddressFamily IPv4 -LinkLayerAddress $macAddresses | Select-Object -Property IPAddress | |
while (@($ipAddresses | Test-Connection -Quiet -Count 1 | Where-Object { !$_ }).Count -ne 0) { | |
Start-Sleep 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment