Made reverse zone generation work with python3.5

ipaddress does not support the reverse pointer in at least python older than 3.6
This commit is contained in:
Sebastian Lohff 2017-04-25 01:20:52 +02:00
parent 098c45e241
commit 67ec9904b2
1 changed files with 23 additions and 10 deletions

View File

@ -100,20 +100,33 @@ class ReverseZone(WhoisObject):
def getZone(self):
net = self.parentNet.getNetwork()
if net.version == 4:
# for these we delegate the full domain
if 0 < net.prefixlen < 32 and net.prefixlen % 8 == 0:
zoneParts = net.reverse_pointer.split(".")
# does not work with python3.4
## for these we delegate the full domain
#if 0 < net.prefixlen < 32 and net.prefixlen % 8 == 0:
# zoneParts = net.reverse_pointer.split(".")
return ".".join(zoneParts[1:])
# return ".".join(zoneParts[1:])
#else:
# # return RFC2317 compliant zone
# return net.reverse_pointer
parts = list(reversed(str(net.network_address).split(".")))
domain = ".".join(parts[4 - net.prefixlen // 8:]) + ".in-addr.arpa."
if net.prefixlen % 8 == 0:
# clean cut!
return domain
else:
# return RFC2317 compliant zone
return net.reverse_pointer
# RFC2317 compliant!
rfc2317Domain = "%s/%s.%s" % (parts[4 - net.prefixlen // 8 - 1], net.prefixlen, domain)
return rfc2317Domain
else:
# ipv6
# thefuck ipaddress lib... _the_ _fuck_
zoneParts = net.reverse_pointer.split(".")[-2 - net.prefixlen // 4:]
## does not work with python3.4
## ipv6
## thefuck ipaddress lib... _the_ _fuck_
#zoneParts = net.reverse_pointer.split(".")[-2 - net.prefixlen // 4:]
#return ".".join(zoneParts)
return ".".join(zoneParts)
parts = list(reversed(net.exploded.split("/")[0].replace(":", "")))[32 - net.prefixlen // 4:]
return ".".join(parts) + ".ip6.arpa."
def get_absolute_url(self):
return reverse("domains:reversezone-show", args=(self.pk,))