브로드 캐스트를 통해 마법 패킷을 보내는 기능을 구현했습니다. 잘 작동하지만 특수한 서버에서 모든 UDP 브로드 캐스트 요청을 수신하고 싶습니다. 작동합니다. 그러나 바이트를 읽고 16 진수 (MAC 주소)로 변환하면 MAC 주소가 잘못됩니다.C# 수신 UPD 브로드 캐스트 바이트 (Magic WOL 패킷) 도착 Mac 가져 오기
에 UDP 요청을 보내기 : MAC과 255.255.255.255 = "001a4d5f84f8"
특수 서버가 성공적인 16 배의 MAC 주소를받을 수 있지만이 변경되었습니다 에서 : 001a4d5f84f8 사람 : 001a4d5f3f3f
아이디어가 있으십니까?
내 기능 :
는//Send Packets
//------------------------------------------------------
string MAC_ADDRESS = "001a4d5f84f8";
UdpClient UDP = new UdpClient();
try
{
IPAddress IPBCast = IPAddress.Parse("255.255.255.255");
UDP.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
int offset = 0;
byte[] buffer = new byte[512];
//first 6 bytes should be 0xFF
for (int y = 0; y < 6; y++)
buffer[offset++] = 0xFF;
//now repeate MAC 16 times
for (int y = 0; y < 16; y++)
{
int i = 0;
for (int z = 0; z < 6; z++)
{
buffer[offset++] =
byte.Parse(MAC_ADDRESS.Substring(i, 2), NumberStyles.HexNumber);
i += 2;
}
}
UDP.EnableBroadcast = true;
UDP.Send(buffer, 512, new IPEndPoint(IPBCast, 0x1));
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message);
UDP.Close();
}
//Receive Packets
//------------------------------------------------------
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0x1);
sock.Bind(iep);
EndPoint ep = (EndPoint)iep;
Console.WriteLine("Ready to receive...");
byte[] data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref ep);
string stringData = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine("received: {0} from: {1}", (StringToHex(stringData)), ep.ToString());
//Convert Received String To Hex
//------------------------------------------------------
public static string StringToHex(string hexstring)
{
var sb = new StringBuilder();
foreach (char t in hexstring)
sb.Append(Convert.ToInt32(t).ToString("x") + " ");
return sb.ToString();
}
당신이 svick 감사, 즉 내가 찾고 정확히입니다. Mac 결과가 정확합니다. 대단히 감사합니다. –