WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);assert wifiManager != null;DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();LogUtils.w(dhcpInfo);// ipaddr 172.20.161.205// gateway 172.20.160.1// netmask 255.255.254.0// dns1 172.16.2.15// dns2 172.16.2.16// DHCP server 172.20.160.1// lease 14400 secondsint ip = dhcpInfo.serverAddress;//此处获取ip为整数类型,需要进行转换final String strIp = intToIp(ip); // 172.20.160.1 ip --->< 27268268LogUtils.w(strIp + " ip --->< " + ip);

其中用到的方法:

private String intToIp(int i) {    return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "."            + ((i >> 24) & 0xFF);}

方法并不是我写的,不知道在哪看到的了。源码里面有类似的,但是比这个方法长。

更多相关文章

  1. Android中设置全屏的方法
  2. [置顶] android调用.net的webservice的例子获取手机的归属地
  3. Android(安卓)反射获取私有方法,成员变量
  4. Android(安卓)杀掉自己进程的方法
  5. android activity 基类 通用方法
  6. Android(安卓)Gridview 禁止滚动的二种方法
  7. How to get the android resolution
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. Android 底部导航栏中间凸起、越界显示
  2. Android 默认水波纹的使用和去除
  3. android开发之android:padding和android:
  4. EditText 文字验证
  5. Windows下git下载android source
  6. Android 获取手机卡相关信息
  7. Android:控件布局(相对布局)RelativeLayout(
  8. Android开发环境搭建
  9. widget(4、spinner)
  10. Android ApiDemos示例解析(140):Views->L