list of DNS servers

826 views
Skip to first unread message

wasabee18

unread,
Jan 12, 2012, 4:17:05 AM1/12/12
to android-ndk
Hi all,

how can I get the list of DNS servers used by the phone? for WiFi?
GPRS/3G?
my initial guess is to get /etc/resolv.conf but it is not present on
the device, neither is it on the emulator.

Thanks for your advice.

Cheers.

Suresh

unread,
Jan 12, 2012, 6:07:20 AM1/12/12
to andro...@googlegroups.com
For WIFI  http://developer.android.com/reference/android/net/wifi/WifiManager.html#getDhcpInfo()  can be used to get dns servers.




--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


wasabee18

unread,
Jan 12, 2012, 11:11:19 PM1/12/12
to android-ndk
Hi Suresh,

thanks for your reply.
I would like to get the DNS server list in native code, without
calling back into java...
Any ideas?

Cheers.

On Jan 12, 6:07 pm, Suresh <suresh.man...@gmail.com> wrote:
> For WIFIhttp://developer.android.com/reference/android/net/wifi/WifiManager.h...()

DroidVPN

unread,
Jan 18, 2012, 8:04:08 AM1/18/12
to android-ndk
Try executing this "getprop net.dns1" and get the output.

You can probably use popen or send the output to a file (eg: getprop
net.dns1 > dns.txt) and then read the file dns.txt.

David Turner

unread,
Jan 18, 2012, 9:50:49 AM1/18/12
to andro...@googlegroups.com
On Wed, Jan 18, 2012 at 2:04 PM, DroidVPN <aed...@gmail.com> wrote:
Try executing this "getprop net.dns1" and get the output.

You can probably use popen or send the output to a file (eg: getprop
net.dns1 > dns.txt)  and then read the file dns.txt.


That would be incredibly complex, when <sys/system_properties.h> provides you with a function (__system_property_get) to read a system property directly from your native code :-)

DroidVPN

unread,
Jan 18, 2012, 11:51:47 AM1/18/12
to android-ndk
Would you mind posting a sample code? Right now I am using what I
posted and doing it your way would be much better :)
Reply all
Reply to author
Forward
0 new messages