I currently have a new project and as an additional security I want to get the workstations MAC address and store it in the Log..
Here's my solution which I based somewhere.....
IPGlobalProperties NetworkProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] NetworkInterfaceCards= NetworkInterface.GetAllNetworkInterfaces();
string macAddress = "";
VeteransBankENT.ApplicationVariables.CurrentHostName = NetworkProperties.HostName;
VeteransBankENT.ApplicationVariables.CurrentHostName = NetworkProperties.DomainName;
if (NetworkInterfaceCards == null || NetworkInterfaceCards.Length < 1)
{
MessageBox.Show(" No network interfaces found.");
}
foreach (NetworkInterface adapter in NetworkInterfaceCards)
{
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet && adapter.OperationalStatus == OperationalStatus.Up)
{
IPInterfaceProperties properties = adapter.GetIPProperties(); // .GetIPInterfaceProperties();
PhysicalAddress address = adapter.GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
for (int i = 0; i < bytes.Length; i++)
{
macAddress += bytes
.ToString("X2");
if (i != bytes.Length - 1)
{
macAddress += "-";
}
}
VeteransBankENT.ApplicationVariables.CurrentHost = macAddress;
break;
}
}