Get DNS - Android Network

Android examples for Network:IP Address

Description

Get DNS

Demo Code


//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;/* www  .ja  v a 2s.  co  m*/
        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();
    }
}

Related Tutorials