Forum Discussion
is there a bug in bytes
There are multiple scripts involving creating Magic Packets for WOL. Basically, all consist of code creating a byte array and sending it via System.Net.Sockets.UdpClient with the 2nd parameter of the send command as the length of the packet. According to the WOL docs the length should be 102 bytes. The math works for some MAC addresses but gives 86 for others. Test below [PS 5.1 ISE]. The point being would a length of 86 still work with WOL
uncomment as needed to test
$MAC = "1A:2B:3C:4D:5E:6F" #should give 102
#$MAC = "74:86:31:7D:19" #should give 86
#$MAC = "1A:86:3C:7D:6F" #should give 102, but try your own to test
#$ByteArray = $MAC -replace "[:\-]" -split "(..)" -ne '' | ForEach-Object { [Byte] "0x$_"}
$ByteArray = $MAC -split ":" | ForEach-Object { [Byte] "0x$_"}
[Byte[]] $MagicPacket = (,0xFF * 6) + ($ByteArray * 16)
$MagicPacket.Length
P.S. Tested determining the length in other languages and all came out 102.
1 Reply
- StanLCopper Contributor
This thread can be removed. User error. I computed the byte length with an invalid MAC address {5 hex bytes} which calculated to 86.