Re: [dnspython-users] What is the equivalent to this code in dnspython?

160 views
Skip to first unread message
Message has been deleted

Anand Buddhdev

unread,
Aug 27, 2019, 9:49:04 AM8/27/19
to THE ENIGMA CODENAMED 3000, dnspython-users
On 27/08/2019 15:30, THE ENIGMA CODENAMED 3000 wrote:

> I know how to read the current dns using dnspython:
>
> import dns
> import dns.resolver
>
> default = dns.resolver.get_default_resolver()
> nameserver = default.nameservers[0]
>
> But I haven't figured out what method I need to use in order to CHANGE the
> address of MY DNS server.

There's a method called "override_system_resolver" for this. It's
documented:

http://www.dnspython.org/docs/1.16.0/dns.resolver-module.html#override_system_resolver

Regards,
Anand
Message has been deleted
Message has been deleted
Message has been deleted

Bob Halley

unread,
Aug 27, 2019, 11:16:50 AM8/27/19
to dnspython-users
dnspython's stub resolver can be used to do queries using:

1) the default resolver object, using dns.resolver.query()
2) a resolver object you make and customize with dns.resolver.Resolver

These two only affect code directly calling the resolver objects.  They do not affect other python code using standard interfaces, e.g. code doing socket.gethostbyname() or socket.getaddrinfo().

If you use the override_system_resolver() method, then you get

3) a resolver that works for all python code in the process where you made the override call.



There's no way to do these two things:

4) Override the resolver for all code, including C libraries, within a single python program

or

5) Override the resolver settings for all applications on the whole system (i.e. other processes).



If you are trying  to do 1 or 2, then setting the "nameservers" field of the resolver object to the list of nameservers you want will work.  This is what I thought you wanted on your github question.

If you want 3, then making the change and then calling dns.resolver.override_system_resolver() will work.  Note that if you make a new resolver object (i.e. solution 2), then you pass that in.

Message has been deleted

Bob Halley

unread,
Aug 27, 2019, 12:03:58 PM8/27/19
to dnspython-users


On Tuesday, August 27, 2019 at 8:55:07 AM UTC-7, THE ENIGMA CODENAMED 3000 wrote:
Thank you for your reply. 

Bottom line: I can't use dnspython to actually change the DNS. It sounds funny, right? :)

But, at the end of the day, I can't use it for my purpose, can I ?

If you are trying to use it to change the nameservice of your whole system, then you can't.  Its purpose is making DNS queries from python, and working with DNS data.  It is not a general purpose stub resolver, or local nameserver, or a tool for modifying the configuration of your operating system.

So, bottom line, "no", assuming I understood what you wanted to do.  (i.e. 4 or 5 in my list).
Reply all
Reply to author
Forward
Message has been deleted
0 new messages