美文网首页
获取本机IP地址

获取本机IP地址

作者: Ed_Lannister | 来源:发表于2022-07-05 09:06 被阅读0次
        <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
      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地址

          本文链接:https://www.haomeiwen.com/subject/qgtsbrtx.html