android应用开发之判断wifi下局域网IP

public String getIpAddress(){
        WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
        {
            WifiInfo info = wm.getConnectionInfo();
           int  hostip = info.getIpAddress();
           String ip = (hostip & 0xFF)+"."+((hostip>>8)&0xFF)+ "." + ((hostip >> 16 ) & 0xFF) +"."+((hostip >> 24 ) & 0xFF);
            Toast.makeText(MainActivity.this, ip, 1).show();
            return ip;
        }
        return null;
    }

你可能感兴趣的:(android应用开发之判断wifi下局域网IP)