Get MAC address C #

I found this code to get the MAC address, but it returns a long string that does not contain’:’.

Is it possible to add’:’ or Split the string and add it yourself?

This is the code:

private object GetMACAddress()
{
string macAddresses = "";
< br /> foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress( ).ToString();
break;
}
}

return macAddresses;
}

It returns the value 00E0EE00EE00, And I want it to display something like 00: E0: EE: 00: EE: 00.

Any ideas?

Thank you.

I am using the following code in the format you want Access mac address:

public string GetSystemMACID()
{
string systemName = System.Windows.Forms.SystemInformation.ComputerName;
try
{
ManagementScope theScope = new ManagementScope("\\" + Environment.MachineName + "\root\cimv2");
ObjectQuery theQuery = new ObjectQuery(" SELECT * FROM Win32_NetworkAdapter");
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
ManagementObjectCollection theCollectionOfResults = theSearcher.Get();

foreach (ManagementObject theCurrentObject in theCollectionOfResults)
{
if (theCurrentObject["MACAddress"] != null)
{
string macAdd = theCurrentOb ject["MACAddress"].ToString();
return macAdd.Replace(':','-');
}
}
}
catch ( ManagementException e)
{
}
catch (System.UnauthorizedAccessException e)
{

}
return string.Empty;
}

I found this code to get the MAC address, but it returns a long string that does not contain’:’.

Is it Can you add’:’ or split the string and add it yourself?

This is the code:

private object GetMACAddress()
{
string macAddresses = "";
< br /> foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress( ).ToString();
break;
}
}

return macAddresses;
}

It returns the value 00E0EE00EE00, And I want it to display something like 00: E0: EE: 00: EE: 00.

Any ideas?

Thank you.

I am using the following code to access the mac address in the format you want:

< p>

public string GetSystemMACID()
{
string systemName = System.Windows.Forms.SystemInformation.ComputerName;
try
{
ManagementScope theScope = new ManagementScope("\\" + Environment.MachineName + "\root\cimv2");
ObjectQuery theQuery = new ObjectQuery("SELECT * FROM Win32_NetworkAdapter");
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
ManagementObjectCollection theCollectionOfResults = theSearcher.Get();

foreach (ManagementObject theCurrentObject in theCollectionOfResults)
{
if (theCurrentObject ["MACAddress"] != null)
{
string macAdd = theCurrentObject["MACAddress"].ToString();
return macAdd.Replace(':','-');
}
}
}
catch (ManagementException e)
{
}
catch (System.UnauthorizedAccessException e)
{

}
return string.Empty;
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1207 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.