[android]代码库
/**
* 获取WIFI的DNS
*
* @return
*/
public static String getDns() {
int BUFFER_SIZE = 1024;
Process localProcess = null;
InputStream in = null;
try {
localProcess = Runtime.getRuntime().exec("getprop net.dns1"); // 获取wifi的dns
in = localProcess.getInputStream();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[BUFFER_SIZE];
int count = -1;
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
outStream.write(data, 0, count);
}
data = null;
String dns = new String(outStream.toByteArray(), "UTF-8");
if(dns.contains("\n")){
dns = dns.replace("\n", "");
}
return dns;
} catch (Exception e) {
e.printStackTrace();
return "";
} finally {
localProcess.destroy();
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
by: 发表于:2018-01-02 10:01:27 顶(0) | 踩(0) 回复
??
回复评论