1 # Samba wrapper for DNS resolvers
3 # Copyright (C) Stanislav Levin <slev@altlinux.org>
4 # Copyright (C) Alexander Bokovoy <ab@samba.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import dns
.reversename
24 class DNSResolver(dns
.resolver
.Resolver
):
25 """DNS stub resolver compatible with both dnspython < 2.0.0
26 and dnspython >= 2.0.0.
28 Set `use_search_by_default` attribute to `True`, which
29 determines the default for whether the search list configured
30 in the system's resolver configuration is used for relative
31 names, and whether the resolver's domain may be added to relative
34 Increase the default lifetime which determines the number of seconds
35 to spend trying to get an answer to the question. dnspython 2.0.0
36 changes this to 5sec, while the previous one was 30sec.
38 def __init__(self
, *args
, **kwargs
):
39 super().__init
__(*args
, **kwargs
)
41 self
.resolve
= getattr(super(), "resolve", self
.query
)
42 self
.resolve_address
= getattr(
48 def reset_defaults(self
):
49 self
.use_search_by_default
= True
57 def _resolve_address(self
, ip_address
, *args
, **kwargs
):
58 """Query nameservers for PTR records.
60 :param ip_address: IPv4 or IPv6 address
64 dns
.reversename
.from_address(ip_address
),
65 rdtype
=dns
.rdatatype
.PTR
,