当前位置:操作系统 > 安卓/Android >>

得到本机ip

public String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInte易做图ce> en = NetworkInte易做图ce.getNetworkInte易做图ces(); en.hasMoreElements();) {
            NetworkInte易做图ce intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException ex) {
        Log.e(LOG_TAG, ex.toString());
    }
    return null;
}

作者“点点滴滴”
 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,