Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String getLocalDns(String dns) { Process process = null; String str = ""; BufferedReader reader = null; try { process = Runtime.getRuntime().exec("getprop net." + dns); reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { str += line; } reader.close(); process.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } process.destroy(); } catch (Exception e) { } } return str.trim(); } }