NetworkService/DeviceInfo.cs

36 lines
823 B
C#
Raw Normal View History

2022-09-04 08:35:19 +09:00
using System.Net;
using System.Text;
namespace NWService
{
public class DeviceInfo
{
private IPAddress ipAddr;
private byte[] macAddr;
public DeviceInfo(IPAddress iPAddress, byte[] macAddressBytes)
{
this.ipAddr = iPAddress;
this.macAddr = macAddressBytes;
}
public IPAddress GetIPAddress()
{
return ipAddr;
}
public string GetMacAddress(char separate = ':')
{
StringBuilder sb = new StringBuilder(18);
foreach (byte b in this.macAddr) {
if (sb.Length > 0)
{
sb.Append(separate);
}
sb.Append(string.Format("{0:X2}", b));
}
return sb.ToString();
}
}
}