实际上,我尝试使用 Xaml 和 C# 获取 Windows 应用商店应用程序的局域网 IP 地址列表。任何人都可以请告诉我如何执行此操作并参考此链接How to get LocalNetwork IP Address For WindowsStore Apps但它显示本地计算机 IP 地址但我想要连接到本地的已连接主机名和 IP 地址的列表局域网中的服务器。这是我的代码:
var hostNamesList = Windows.Networking.Connectivity.NetworkInformation
.GetHostNames();
foreach (var entry in hostNamesList)
{
if (entry.Type == Windows.Networking.HostNameType.DomainName)
{
var icp = NetworkInformation.GetInternetConnectionProfile();
if (icp != null && icp.NetworkAdapter != null)
{
var hostname =
NetworkInformation.GetHostNames().SingleOrDefault(
hn =>
hn.IPInformation != null &&
hn.IPInformation.NetworkAdapter.NetworkAdapterId ==
icp.NetworkAdapter.NetworkAdapterId);
MessageDialog msg = new MessageDialog(hostname.CanonicalName);
await msg.ShowAsync();
MessageDialog msg1 = new MessageDialog(entry.RawName);
await msg1.ShowAsync();
}
}
}
}