Cross-platform way to retrieve the current (Operative system) DNS server IP address in python
hansmu at xs4all.nl
Fri Apr 30 06:01:59 EDT 2010
> It's not my ip address that I want to discover... I want to discover
> my default dns server ip address.
> This ip is stored in an operative system basis.
> Dos anyone know how to get it ?
You asked for a cross-platform solution; there probably isn't one.
The code below works on Unix and MacOS X.
If you can find code that works on Windows, you can cobble together
somthing that will work on most platforms.
dns_ips = 
for line in file('/etc/resolv.conf', 'r'):
columns = line.split()
if columns == 'nameserver':
Hope this help,
More information about the Python-list