获取当前的ip-address Xamarin.Forms(跨平台)
如何获取Xamarin.Forms(跨平台)的当前IP地址? WifiManager我不能使用而且不能包含WifiManager?
public string MyIp; foreach (IPAddress adress in Dns.GetHostAddresses(Dns.GetHostName())) { MyIp = "IP Adress: " + adress.ToString(); SettingsTab.IP_Adress = MyIp; break; }
试着这样做:
上述就是C#学习教程:获取当前的ip-address Xamarin.Forms(跨平台)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
public static string GetIPAddress() { var AllNetworkInterfaces = Collections.List(Java.Net.NetworkInterface.NetworkInterfaces); var IPAddres = ""; foreach (var interfaces in AllNetworkInterfaces) { if (!(interfaces as Java.Net.NetworkInterface).Name.Contains("eth0")) continue; var AddressInterface = (interfaces as Java.Net.NetworkInterface).InterfaceAddresses; foreach (var AInterface in AddressInterface) { if(AInterface.Broadcast != null) IPAddres = AInterface.Address.HostAddress; } } return IPAddres; }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/959504.html