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 label1.Text = ipadd.Address.ToString();//获取ip } } }
已有 4255 位网友参与,快来吐槽:
发表评论