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.
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;
}
p>