def squery(self, name, rtype): if type(name) == str: name = dn.fromstring(name) if not name.rooted: namelist = [name + prefix for prefix in self.prelist] + [name + dn.fromstring(".")] else: namelist = [name] for name in namelist: packet = proto.packet() packet.setflags(["recurse"]) packet.addq(rec.rrhead(name, rtype)) res = self.resolve(packet) if res.rescode == 0: break return res
def __init__(self, name, cname, function): self.name = name if type(cname) == str: self.cname = dn.fromstring(cname) else: self.cname = cname self.function = function
def convdata(self, dtype, data): if dtype == "4": if type(data) != str: raise error("IPv4 address must be a string") if len(data) == 4: d = data else: d = socket.inet_pton(socket.AF_INET, data) if dtype == "6": if type(data) != str: raise error("IPv6 address must be a string") if len(data) == 16 and data.find(":") == -1: d = data else: d = socket.inet_pton(socket.AF_INET6, data) if dtype == "d": if type(data) == str: d = dn.fromstring(data) elif isinstance(data, dn.domainname): d = data else: raise error("Domain name must be either proper or string") if dtype == "s": d = str(data) if dtype == "i": d = int(data) return d
def __init__(self, origin, handler): if type(origin) == str: self.origin = dn.fromstring(origin) self.origin.rooted = True else: self.origin = origin self.handler = handler
def __init__(self, conffile = "/etc/resolv.conf"): nslist = [] prelist = [] a = open(conffile, "r") for line in (l.strip() for l in a): p = line.find(" ") if p >= 0: c = line[:p] line = line[p + 1:] if c == "nameserver": try: socket.inet_pton(socket.AF_INET, line) except socket.error: pass else: nslist += [(socket.AF_INET, line, 53)] try: socket.inet_pton(socket.AF_INET6, line) except socket.error: pass else: nslist += [(socket.AF_INET6, line, 53)] if c == "domain" or c == "search": # How do these differ? prelist += line.split() a.close() rl = [] for ns in nslist: rl += [resolver(ns, False, True)] self.resolver = multiresolver(rl) self.prelist = [] for prefix in prelist: pp = dn.fromstring(prefix) pp.rooted = True self.prelist += [pp]
def __init__(self, name, algo, secret): if type(name) == str: self.name = dn.fromstring(name) else: self.name = name if type(algo) == str: self.algo = algobyname[algo] else: self.algo = algo self.secret = secret
def __init__(self, name = None, rtype = None, rclass = None): if rclass is None: rclass = CLASSIN if type(name) == str: self.name = dn.fromstring(name) else: self.name = name if type(rtype) == str: self.rtype = rtypebyname(rtype) if self.rtype is None: raise error("no such rtype " + rtype) else: self.rtype = rtype self.rclass = rclass
def readkeys(keyfile): close = False if type(keyfile) == str: keyfile = open(keyfile, "r") close = True try: ret = [] for line in keyfile: words = line.split() if len(words) < 3: continue ret += [tsigkey(dn.fromstring(words[0]), words[1], base64.b64decode(words[2]))] return ret finally: if close: keyfile.close()