检索设备的IP地址 [英] Retrieve IP address of device
本文介绍了检索设备的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Xamarin.Android并编写了以下代码:
I am using Xamarin.Android and wrote the following code:
public TextView text;
text = FindViewById<TextView>(Resource.Id.viewIP);
foreach (IPAddress adress in Dns.GetHostAddresses(Dns.GetHostName()))
{
text.Text = "IP Adress: " + adress;
}
但是,当我打开应用程序时,它会立即关闭.我是否使用正确的方式来获取设备的IP地址?
However, when I open the application it shuts down immediately. Am I using the correct way of getting the IP address' of the device?
推荐答案
来自 Xamarin论坛
Java.Util.IEnumeration networkInterfaces = NetworkInterface.NetworkInterfaces;
while(networkInterfaces.HasMoreElements)
{
Java.Net.NetworkInterface netInterface =
(Java.Net.NetworkInterface)networkInterfaces.NextElement();
Console.WriteLine(netInterface.ToString());
}
这篇关于检索设备的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文