首页 > 代码库 > java获取本机IP地址

java获取本机IP地址

/** * WIFI没打开:ip为127.0.0.1 * 获取本机IP地址字符串  * @return */public String getWifiIp() {    if (!getWifiEnabled()) {        return "127.0.0.1";    }    WifiInfo wifiInfo = mWifiManager.getConnectionInfo();    int ipAddress = wifiInfo.getIpAddress();    String ip = intToIp(ipAddress);    Log.E(TAG, "ip: " + ip);    return ip;} private String intToIp(int ip) {    return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + ((ip >> 24) & 0xFF);}

 

java获取本机IP地址