I am working on a Device finder at the moment and i am really struggeling with the code because normally i write microcontroller code.
I hope somebody could help me out.
The goal is to receive the client IP from an UDP Broadcast to a manufacturer specific port. This is working fine for me. I send the Broadcast and i got back the data send from Device:
00-00-00-F7-00-20-A0-06-58-39-30-12-63-16-00-00-62-A7-52-0B-FF-00-00-00-00-80-A3-BE-2F-XX
Its include the MAC Adress of the device (last 6 HEX snippets)
But i cant find the Senders(Client) IP address
How can i save the whole packedge send from the client? including the IP? Because in Wireshark i see the whole package (Send from: 192.xxx...)
Thank you so much! Best regards
My code is:
Byte[] data = { 0x00, 0x00, 0x00, 0xF6 };
//string s1 = Encoding.UTF8.GetString(data);
int port = 30718;
string Antwort;
// Socket definieren
Socket bcSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//bcSocket.Connect(new IPEndPoint(IPAddress.Broadcast, port));
// EndPoint definieren bzw. Ziel des Broadcastes
IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, port);
// Optionen auf den Socket binden
bcSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
// Broadcast senden
bcSocket.SendTo(data, iep);
bcSocket.ReceiveTimeout = 5000;
byte[] test = new byte[1024];
bcSocket.Receive(test);
Antwort = System.Text.Encoding.Default.GetString(test).Trim(new char[] { '\0' });
textBox_IPAdresse.Text = Antwort;
string antworthex = BitConverter.ToString(test);
textBox1.Text = antworthex;
// Socket schliessen, nach erfolgreichem Senden des Broadcastes
bcSocket.Close();