获取本机IP地址

    
   

  private String getlocalip(){
    WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ipAddress = wifiInfo.getIpAddress();
    Log.d(TAG, "int ip "+ipAddress);
    if(ipAddress == 0) return "127.0.0.1";
    return ((ipAddress & 0xff)+"."+(ipAddress>>8 & 0xff)+"."
            +(ipAddress>>16 & 0xff)+"."+(ipAddress>>24 & 0xff));
  }

你可能感兴趣的:(获取本机IP地址)