Skip to content

Instantly share code, notes, and snippets.

@Trinea
Last active June 4, 2017 05:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trinea/8553088 to your computer and use it in GitHub Desktop.
Save Trinea/8553088 to your computer and use it in GitHub Desktop.
get the current DNS servers for Android
Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
Method method = SystemProperties.getMethod("get", new Class[] { String.class });
ArrayList<String> servers = new ArrayList<String>();
for (String name : new String[] { "net.dns1", "net.dns2", "net.dns3", "net.dns4", }) {
String value = (String) method.invoke(null, name);
if (value != null && !"".equals(value) && !servers.contains(value))
servers.add(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment