0

This is my code for find MAC address, but it show same result when I run this in any device?

 public string GetMACAddress1()
    {
        try
        {
            NetworkInterface[] anics=NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in anics)
            {
                if (amacaddress == String.Empty)
                {
                    IPInterfaceProperties properties =adapter.GetIPProperties();
                    amacaddress = adapter.GetPhysicalAddress().ToString();                       
                }
            }
            return "MAC Address is :- " + amacaddress;
        }
        catch
        {
            return "error";
        }
    }

How can I got this.?

7
  • Your method is only going to ever return the value of the first MAC address found. Why would this change? Commented Jul 5, 2018 at 6:42
  • That's right, as soon as you get the first value, amacaddress won't be Empty anymore, so you won't enter the if anymore. Therefore, the rest of your foreach loop is useless Commented Jul 5, 2018 at 6:44
  • How to resolve it? Commented Jul 5, 2018 at 7:07
  • What is the purpose of this function? What are you actually trying to achieve? Commented Jul 6, 2018 at 0:43
  • if someone view my site second time with same device, i want to show items similar to his previous selections. Commented Jul 6, 2018 at 7:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.