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 activity 基类 通用方法
  2. Android 反射获取私有方法,成员变量
  3. Android 杀掉自己进程的方法
  4. Android Gridview 禁止滚动的二种方法
  5. Android 去掉title bar的3个方法
  6. android抓取各种log的方法
  7. android 捕获返回(后退)按钮事件的两种方法
  8. ubuntu 不是 识别 android 设备 解决方法

随机推荐

  1. 修改购物车产品数量
  2. Cause: InvokeDynamic not supported
  3. [Android(安卓)Memory] App调试内存泄露
  4. android-async-http将json封装到body体中
  5. x4412开发板&ibox卡片电脑项目实战5-修改
  6. SurfaceView的使用
  7. Android术语详解
  8. layout_weight 学习笔记.
  9. Android(安卓)技术干货收集
  10. Android(安卓)源码中增加自定义系统服务