1NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); 2foreach (NetworkInterface adapter in nics) 3{ 4 //判断是否为以太网卡 5 //Wireless80211 无线网卡 Ppp 宽带连接 6 //Ethernet 以太网卡 7 //这里篇幅有限贴几个常用的,其他的返回值大家就自己百度吧! 8 if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet) 9 { 10 //获取以太网卡网络接口信息 11 IPInterfaceProperties ip = adapter.GetIPProperties(); 12 //获取单播地址集 13 UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses; 14 foreach (UnicastIPAddressInformation ipadd in ipCollection) 15 { 16 //InterNetwork IPV4地址 InterNetworkV6 IPV6地址 17 //Max MAX 位址 18 if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork) 19 //判断是否为ipv4 20 Console.WriteLine(ipadd.Address.ToString());//获取ip 21 } 22 } 23}
C# 获取 ipv4的方法
Stella981
2021-10-11
1142 0 0
点赞
收藏
评论区
加载中...