Avatar of abgconsulting
abgconsulting
 asked on

Get Mac Address

i get my mac address in this format xxxxxxxxxx but i want it in this format xx:xx:xx:xx:xx.
somenone have an idea on it.
Thx
Pms
C#

Avatar of undefined
Last Comment
for_yan

8/22/2022 - Mon
wdosanjos

Please post your code that gets the mac address.
abgconsulting

ASKER
  String MacAddress = string.Empty;
            foreach (NetworkInterface mac in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (mac.OperationalStatus == OperationalStatus.Up)
                {
                    MacAddress = mac.GetPhysicalAddress().ToString();
                    break;
                }
            }
           
            return MacAddress;
ASKER CERTIFIED SOLUTION
wdosanjos

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
for_yan

This code comes from
http://www.dotnetspider.com/resources/4889-Get-MAC-address-your-system.aspx
Perhpas it could help:

public string GetMACAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}

return MACAddress;
}

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck