private IList<IPInfo> GetIPInfo()
{
IList<IPInfo> rIPList = new List<IPInfo>();
NetworkInterface[] NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface NetworkIntf in NetworkInterfaces)
{
IPInterfaceProperties IPInterfaceProperties = NetworkIntf.GetIPProperties();
UnicastIPAddressInformationCollection UnicastIPAddressInformationCollection = IPInterfaceProperties.UnicastAddresses;
foreach (UnicastIPAddressInformation UnicastIPAddressInformation in UnicastIPAddressInformationCollection)
{
if (UnicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork)
{
string IP = UnicastIPAddressInformation.Address.ToString();
if (IP != "127.0.0.1")
{
IPInfo info = new IPInfo();
info.IPAddress = IP;
info.OptStatus = NetworkIntf.OperationalStatus;
info.DisplayCaption = info.IPAddress;
if (info.OptStatus == OperationalStatus.Up)
{
info.DisplayCaption = info.DisplayCaption + " [已连接]";
}
else
{
info.DisplayCaption = info.DisplayCaption + " [已断开]";
}
rIPList.Add(info);
}
}
}
}
return rIPList;
}
c# 获取网卡信息
最新推荐文章于 2024-04-13 13:27:10 发布