Windows Store APP- C# to get IP Address

using Windows.Networking.Connectivity;

  public String GetIPString()
        {
            String ipString = String.Empty;
            var icp = NetworkInformation.GetInternetConnectionProfile();
            if (icp != null && icp.NetworkAdapter != null)
            {
                var hostname =
                    NetworkInformation.GetHostNames().SingleOrDefault(
                        hn =>
                        hn.IPInformation != null &&   hn.IPInformation.NetworkAdapter != null
                        && hn.IPInformation.NetworkAdapter.NetworkAdapterId
                        == icp.NetworkAdapter.NetworkAdapterId);

                if (hostname != null)
                {
                    // the ip address
                    ipString = hostname.CanonicalName;
                }
            }

            return ipString;
        }

--- Retrieve Host Name.

 public static IReadOnlyList<HostName> GetHostNames()

 

posted on 2013-07-27 15:14  Simon Han  阅读(359)  评论(0编辑  收藏  举报