直接上一段用于内网获取本机ip地址的方法,更全面的可以先获取本机网络类型,在获取ip
- /// <summary>
- /// 获取本地连接ip
- /// </summary>
- /// <returns></returns>
- private string getLocalIp()
- {
- NetworkInterface[] interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
- int len = interfaces.Length;
- string localIP = "未找到";
- for (int i = 0; i < len; i++)
- {
- NetworkInterface ni = interfaces[i];
- if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet || ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
- {
- if (ni.Name == "本地连接" || ni.Name=="无线网络连接")
- {
- IPInterfaceProperties property = ni.GetIPProperties();
- foreach (UnicastIPAddressInformation ip in property.UnicastAddresses)
- {
- if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
- {
- localIP= ip.Address.ToString();
- }
- }
- }
- }
-
- }
- return localIP;
- }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。