private void autoSetWifi() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); String ip = Formatter.formatIpAddress(wifi.getDhcpInfo().ipAddress); Process process; String targetStr = ""; try { process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); os.writeBytes("netcfg\n"); os.writeBytes("exit\n"); os.flush(); BufferedReader mReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024); String line; while ((line = mReader.readLine()) != null) { if (line.length() == 0) { continue; } if (line.contains(ip)) { targetStr = line; } } } catch (IOException e) { e.printStackTrace(); } targetStr = targetStr.split(" ")[0]; targetStr = targetStr.split("\t")[0]; Logging.updateDebug(targetStr); EditText et = (EditText) findViewById(R.id.wifi_edittext); et.setText(targetStr); }