Skip to content

Instantly share code, notes, and snippets.

@mono0x
Last active February 26, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mono0x/35b3ce1f23d4bbd10b09c5de6a9d487d to your computer and use it in GitHub Desktop.
Save mono0x/35b3ce1f23d4bbd10b09c5de6a9d487d to your computer and use it in GitHub Desktop.
$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