频道栏目
首页 > 资讯 > Android > 正文

android 获取当前手机的 DHCP 信息ip,server 等操作实例教程

18-07-30        来源:[db:作者]  
收藏   我要投稿

android 获取当前手机的 DHCP 信息ip,server 等操作实例教程

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 seconds
int ip = dhcpInfo.serverAddress;
//此处获取ip为整数类型,需要进行转换
final String strIp = intToIp(ip); // 172.20.160.1 ip --->< 27268268
LogUtils.w(strIp + " ip --->< " + ip);

其中用到的方法:

private String intToIp(int i) {
 return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "."
+ ((i >> 24) & 0xFF);
}
相关TAG标签
上一篇:多线程下载mwget工具linux快速下载工具
下一篇:Python模块常用的小技巧
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站