|
你试试看。
- <火山程序 类型 = "通常" 版本 = 1 />
- 方法 取以太网IP <公开 静态 类型 = 文本型 编辑时信息 = "73FF8, 0, 0, 0"
- @java.导入 = "android.net.ConnectivityManager\nandroid.net.NetworkCapabilities\nandroid.net.Network\nandroid.net.LinkProperties\njava.net.InetAddress\njava.net.Inet4Address\nandroid.net.LinkAddress"
- @禁止流程检查 = 真 @安卓.系统需求 = 21 @安卓.权限需求 = 安卓权限.获取网络状态>
- {
- @ ConnectivityManager cm = (ConnectivityManager) @dt<应用程序>.sGetApp().getSystemService(android.content.Context.CONNECTIVITY_SERVICE);
- @ if (cm == null) return "";
- @ Network[] networks = cm.getAllNetworks();
- @ for (Network network : networks) {
- @ NetworkCapabilities nc = cm.getNetworkCapabilities(network);
- @ if (nc != null && nc.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
- @ LinkProperties linkProperties = cm.getLinkProperties(network);
- @ if (linkProperties != null) {
- @ for (LinkAddress linkAddress : linkProperties.getLinkAddresses()) {
- @ InetAddress address = linkAddress.getAddress();
- @ if (!address.isLoopbackAddress() && address instanceof Inet4Address) {
- @ return address.getHostAddress();
- @ }
- @ }
- @ }
- @ }
- @ }
- @ return "";
- }
复制代码 |
|