You can use the recognizer functions as described in the answer to this question or read the nameserver addresses from a file /etc/resolv.conf, which is a simple text file, for example
# Generated by NetworkManager
nameserver x.x.x.x
nameserver y.y.y.y
where x.x.x.xand y.y.y.yare the IP addresses.
source
share