private IPEndPoint point;
private UdpClient client = new UdpClient();
/**
///
/// 字符串轉16進制字節數組
///
///
///
public static byte[] strToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
///
/// 拼裝MAC魔術封包
///
///
///
public static byte[] getMagicPacket(string macString)
{
byte[] returnBytes = new byte[102];
string commandString = "FFFFFFFFFFFF";
for (int i = 0; i < 6; i++)
returnBytes[i] = Convert.ToByte(commandString.Substring(i * 2, 2), 16);
byte[] macBytes = strToHexByte(macString);
for (int i = 6; i < 102; i++)
{
returnBytes[i] = macBytes[i % 6];
}
return returnBytes;
}
這是網上找的代碼,然後我自己建了一個按鈕。被喚醒機器的mac地址和ip地址都知道。port是什麼,是自己端口還是被喚醒機器端口,還有什麼需要注意的?
參考這裡:http://bbs.zxwindow.com/forum.php?mod=viewthread&tid=140588