您的位置:首页 > 移动开发

Windows Store APP- C# to get IP Address

2013-07-27 15:14 441 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: