Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6241347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:45:09+00:00 2026-05-24T11:45:09+00:00

I’ve implemented a function to send magic packets over a broadcast. It Works fine,

  • 0

I’ve implemented a function to send magic packets over a broadcast.
It Works fine, but I would like to receive all UDP broadcast requests on a special server.
Works as well.
But if I try to read the bytes and convert the bytes to hexadecimal (MAC Address) back, the mac address will be wrong.

Send UDP Request to: 255.255.255.255 with MAC = “001a4d5f84f8”

The special server receive successfull 16 times the MAC Address, but it has changed:
From:
001a4d5f84f8
To:
001a4d5f3f3f

Any ideas?

My functions:

//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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:45:10+00:00Added an answer on May 24, 2026 at 11:45 am

    Your problem is Encoding.ASCII.GetString(). It can read strings encoded using ASCII, but that’s not what you’re sending. You have to decode the bytes as bytes.

    If you want the result as string, you can use something like

    string.Join("", bytes.Select(b => b.ToString("x2")))
    

    Here, bytes is a sequence of the bytes you want to convert to string.

    (If you’re not on .Net 4, you need to add .ToArray() after the Select().)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.