Beispiel #1
0
    def opt_reverse(self, net_file):
        """Write out reverse zone, in the form ADDRESS/NETMASK:FILE"""
        if ":" not in net_file:
            raise usage.UsageError("--reverse= value must contain semicolon")
        addr_nm, filename = net_file.split(":", 1)

        if "/" not in addr_nm:
            raise usage.UsageError("--reverse= value must have netmask")
        addressString, netmaskString = addr_nm.split("/", 1)

        try:
            address = dns.aton(addressString)
        except OSError as e:
            raise usage.UsageError("--reverse= address is invalid: %s" % e)

        try:
            netmask = dns.aton(netmaskString)
        except OSError as e:
            raise usage.UsageError("--reverse= netmask is invalid: %s" % e)

        self.opts.setdefault("reverse", []).append({
            "address": address,
            "netmask": netmask,
            "filename": filename,
        })
Beispiel #2
0
 def isInNet(self, ipAddress):
     net = dns.aton(self.address)
     mask = dns.aton(self.mask)
     ip = dns.aton(ipAddress)
     if ip & mask == net:
         return 1
     return 0
Beispiel #3
0
    def getReverse(self, domain):
        ip = dns.aton(self.address)
        mask = dns.aton(self.mask)
        broadcast = dns.ntoa(ip | ~mask)

        return (("; %s\n" % self.dn) +
                formatPTR(self.name + "." + domain, self.address) +
                formatPTR("broadcast." + self.name + "." + domain, broadcast))
Beispiel #4
0
    def getForward(self):
        ip = dns.aton(self.address)
        mask = dns.aton(self.mask)
        ipmask = dns.ntoa(mask)
        broadcast = dns.ntoa(ip | ~mask)

        return (("; %s\n" % self.dn) +
                formatIPAddress(self.name, self.address) +
                formatIPAddress("netmask." + self.name, ipmask) +
                formatIPAddress("broadcast." + self.name, broadcast))
Beispiel #5
0
 def printZone(self):
     print("#" + self.dn)
     printIPAddress(self.name, self.address)
     printPTR(self.name, self.address)
     ip = dns.aton(self.address)
     mask = dns.aton(self.mask)
     ipmask = dns.ntoa(mask)
     broadcast = dns.ntoa(ip | ~mask)
     printIPAddress("netmask." + self.name, ipmask)
     printIPAddress("broadcast." + self.name, broadcast)
     printPTR("broadcast." + self.name, broadcast)
Beispiel #6
0
 def isInNet(self, ipAddress):
     try:
         net = dns.aton(self.address)
         mask = dns.aton(self.mask)
         ip = dns.aton(ipAddress)
     except OSError:
         # no need to log here, higher levels will log a warning
         # when they see the address is in no net
         return False
     if ip & mask == net:
         return True
     return False
Beispiel #7
0
    def _cbGotNets(nets, forward, reverse):
        r = []
        for e in nets:
            net = Net(
                str(e.dn),
                str(only(e, "cn")),
                str(only(e, "ipNetworkNumber")),
                str(only(e, "ipNetmaskNumber")),
            )
            print(net.getForward(), file=forward)

            for data in reverse:
                ip = dns.aton(net.address)
                if ip & data["netmask"] == data["address"]:
                    if "file" not in data:
                        data["tempname"] = "%s.%d.tmp" % (data["filename"], os.getpid())
                        data["file"] = open(data["tempname"], "w")
                    print(net.getReverse(domain), file=data["file"])
                    net.reverseZone = data
            r.append(net)
        return r
Beispiel #8
0
 def test_CIDR(self):
     for i in range(0, 33):
         mask = dns.ntoa(dns.aton(i))
         self.assertEquals(dns.netmaskToNumbits(mask), i)
 def test_CIDR(self):
     for i in range(0, 33):
         mask = dns.ntoa(dns.aton(i))
         self.assertEqual(dns.netmaskToNumbits(mask), i)