Skip to content

Commit

Permalink
Add interface to get mac adress.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogoson committed Oct 2, 2019
1 parent 03bec90 commit 9486a4e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions WinCommon/Network/NetworkUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*************************************************************************/

using MGS.WinLibrary;
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;

namespace MGS.WinCommon.Network
{
Expand Down Expand Up @@ -39,6 +42,34 @@ public static NetworkConnState GetNetworkConnectState()
}
return NetworkConnState.OFFLINE;
}

/// <summary>
/// Get the mac address of pc.
/// </summary>
/// <returns>Mac address of pc.</returns>
public static ICollection<string> GetMacAddress()
{
var macAdress = new List<string>();
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var item in interfaces)
{
var physicalAddress = item.GetPhysicalAddress();
if (physicalAddress == null)
{
continue;
}

var addressBytes = physicalAddress.GetAddressBytes();
if (addressBytes == null)
{
continue;
}

var adress = BitConverter.ToString(addressBytes);
macAdress.Add(adress);
}
return macAdress;
}
#endregion
}
}

0 comments on commit 9486a4e

Please sign in to comment.