I'm not aware of any general purpose solution. The previously posted code may work for you, or it may not. I believe it has issues...
Could you give more background on your goal/problem? i.e... Will you be "connected" at the time the script is run? How do you connect to the internet? How many network interfaces do you have? What type of host is the script to be run on... etc -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Matthew Sherborne Sent: Thursday, June 27, 2002 1:50 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: How to find out DNS ? A wrote: >Hi, >Is there a way how to find out, from Python , what primary or >secondary DNS I use when connecting to internet? >Thanks for help >Ladislav > >_______________________________________________ >ActivePython mailing list >[EMAIL PROTECTED] >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs >Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython > > > > > def getServersFromOS(self): if sys.platform in ('win32', 'nt'): return self.getServersFromWin32() elif sys.platform == 'posix': return self.getServersFromPosix() else: return [] def getServersFromWin32(self): import _winreg servers = [] x = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) try: y = _winreg.OpenKey(x, r'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters') except EnvironmentError: # so it isn't NT/2000/XP # windows ME, perhaps? try: # for Windows ME y = _winreg.OpenKey(x, r'SYSTEM\CurrentControlSet\Services\VxD\MSTCP') nameserver = _winreg.QueryValueEx(y, 'NameServer')[0] if nameserver and not (nameserver in servers): servers += nameserver.split(',') except EnvironmentError: pass return servers def getServersFromPosix(self): """"Parses the /etc/resolv.conf file and sets defaults for name servers"""" lines = open('/etc/resolv.conf').readlines() servers = [] for line in lines: line = line.strip() if not line or line[0] == ';' or line[0] == '#': continue fields=string.split(line) if fields[0] == 'domain': defaults['domain'] = fields[1] elif fields[0] == 'search': pass elif fields[0] == 'options': pass elif fields[0] == 'sortlist': pass elif fields[0] == 'nameserver': servers.append(fields[1]) return servers GBU Matthew Sherborne _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
