最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android获取手机ip程序代码
时间:2022-11-14 22:17:39 编辑:袖梨 来源:一聚教程网
实例
| 代码如下 | 复制代码 |
|
public String getLocalIpAddress() { public String getLocalMacAddress(Context context) { |
|
安卓4.0系统的手机,按上面的方法默认会先获取到ipv6的地址,有时候我们只想要ipv4的地址
| 代码如下 | 复制代码 |
| /** * 用来获取手机拨号上网(包括CTWAP和CTNET)时由PDSN分配给手机终端的源IP地址。 * * @return * @author SHANHY */ public static String getPsdnIp() { try { for (Enumeration NetworkInterface intf = en.nextElement(); for (Enumeration InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { //if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet6Address) { return inetAddress.getHostAddress().toString(); } } } } catch (Exception e) { } return ""; } |
|
相关文章
- 《Pokemon TCG》Mega Evolution - Chaos Rising 系列 Crobat 全图卡牌情报公开 04-25
- TGA年度最佳《光与影 33号远征队》销量爆炸 官宣突破八百万 04-25
- 刺客信条 黑旗记忆重置版现价格异常,豪华版短时直降10美元引热议 04-25
- 全本小说账号怎么注销 04-25
- 异环新手实用开荒建议指南 04-25
- 怎么解锁《Kiln》中的所有成就 04-25