首页 > 其他分享 >android-code-getip

android-code-getip

时间:2022-11-08 10:36:10浏览次数:36  
标签:code enumIpAddr nextElement hasMoreElements Enumeration en inetAddress android g


public String getIP() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()
&& !inetAddress.isLinkLocalAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}


标签:code,enumIpAddr,nextElement,hasMoreElements,Enumeration,en,inetAddress,android,g
From: https://blog.51cto.com/u_13316945/5831989

相关文章

  • android--查看keystore文件签名信息
    Java\jdk1.6.0_14\bin\keytool-list-v-keystore keystoreName输入密码就可以了。C:\tmp\0>keytool密钥和证书管理工具命令: -certreq      生......
  • android_文本垂直滚动
    这个自定义view主要实现的是垂直文本自动滚动,当文本高度超出垂直高度时自动滚动。也可以修改成其他条件触发滚动。参考了网上一篇文章,找不到出处了。packagecom.serviatech......
  • android-code-saveLog
    一个工具类。第一个用来将logcat保存到文件,第二个用来获得logcat字符串。publicclassLogcat{publicfinalstaticStringTAG="VLC/Util/Logcat";/***Wr......
  • android-code-调整音量
    这是不弹出界面的方式:/***@paramvalue*0-15*/publicvoiddealCMDSound(intvalue){AudioManagermAudioManager=(AudioManager)getSy......
  • vscode常用配置的json文件
    {"editor.parameterHints":true,"editor.quickSuggestions":{"other":true,"comments":true,"strings":true},"wind......
  • 小程序开发vscode常用插件
    wechat-snippet微信小程序代码辅助,代码片段自动完成minapp微信小程序标签、属性的智能补全(同时支持原生小程序、mpvue和wepy框架,并提供snippets)wxapp-helper微信......
  • vscode常用配置
    {"editor.quickSuggestions":{"other":true,"comments":true,"strings":true},"editor.fontSize":16,"editor.wordWrap":"off",//永不......
  • leetcode 35. 搜索插入位置 js 实现
    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。请必须使用时间复杂度为 O(logn) 的算法。......
  • [LeetCode] 1323. Maximum 69 Number
    Youaregivenapositiveinteger num consistingonlyofdigits 6 and 9.Return themaximumnumberyoucangetbychanging atmost onedigit(6 becomes......
  • leetcode 300. 最长递增子序列 js 动态规划实现
    给你一个整数数组nums,找到其中最长严格递增子序列的长度。子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7]是数组[0......