最新下载
热门教程
- 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 ""; } |
|
相关文章
- 教育改革最新方向与实施路径 - 2026年政策解读 06-11
- Claude企业版版权风险说明:6项企业合规检查清单 06-11
- 《迷你世界》地下基地怎么建造-地下基地建造详细步骤 06-11
- 《无敌找茬王2》宫廷宴会通关攻略 06-11
- 龙族:卡塞尔之门辉夜姬介绍 06-11
- 梦幻新诛仙轻享版职业全解 梦幻新诛仙轻享角色全解析 06-11