Default DNS

Peter Hansen peter at
Wed Nov 21 05:46:01 CET 2001

A wrote:
> Is there any possibility in Python to find out my primary or
> secondary DNS when using Dial Up connection from Windows?

Something like the following might be the quickest approach:

>>> import os,re
>>> text = os.popen('ipconfig /all').read()
>>> dns ='DNS Servers[ .]*:\s+(\S+)\s*(\S+)?', text).groups()
>>> dns
('', '')

I tried using a pattern like this at first, but it only returned a
result of (' :',) and I'm not sure why:

>>> dns ='DNS Servers[ .]*:((?:\s+)\S+)+', text).groups()
>>> dns
(' :',)

I suppose the non-grouping group (?:...) cannot be nested inside
another group?

Peter Hansen, P.Eng.
peter at

More information about the Python-list mailing list