NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
    //判断是否为以太网卡
    //Wireless80211         无线网卡    Ppp     宽带连接
    //Ethernet              以太网卡   
    //这里篇幅有限贴几个常用的,其他的返回值大家就自己百度吧!
    if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
    {
        //获取以太网卡网络接口信息
        IPInterfaceProperties ip = adapter.GetIPProperties();
        //获取单播地址集
        UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
        foreach (UnicastIPAddressInformation ipadd in ipCollection)
        {
            //InterNetwork    IPV4地址      InterNetworkV6        IPV6地址
            //Max            MAX 位址
            if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork)
                //判断是否为ipv4
                Console.WriteLine(ipadd.Address.ToString());//获取ip
        }
    }
}

  

相关文章:

  • 2021-08-12
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-12-05
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案