Browse Source

Made reverse zone generation work with python3.5

ipaddress does not support the reverse pointer in at least python older than 3.6
Sebastian Lohff 4 years ago
parent
commit
67ec9904b2
1 changed files with 25 additions and 12 deletions
  1. 25
    12
      domains/models.py

+ 25
- 12
domains/models.py View File

@@ -100,20 +100,33 @@ class ReverseZone(WhoisObject):
100 100
 	def getZone(self):
101 101
 		net = self.parentNet.getNetwork()
102 102
 		if net.version == 4:
103
-			# for these we delegate the full domain
104
-			if 0 < net.prefixlen < 32 and net.prefixlen % 8 == 0:
105
-				zoneParts = net.reverse_pointer.split(".")
106
-
107
-				return ".".join(zoneParts[1:])
103
+			# does not work with python3.4
104
+			## for these we delegate the full domain
105
+			#if 0 < net.prefixlen < 32 and net.prefixlen % 8 == 0:
106
+			#	zoneParts = net.reverse_pointer.split(".")
107
+
108
+			#	return ".".join(zoneParts[1:])
109
+			#else:
110
+			#	# return RFC2317 compliant zone
111
+			#	return net.reverse_pointer
112
+			parts = list(reversed(str(net.network_address).split(".")))
113
+			domain = ".".join(parts[4 - net.prefixlen // 8:]) + ".in-addr.arpa."
114
+			if net.prefixlen % 8 == 0:
115
+				# clean cut!
116
+				return domain
108 117
 			else:
109
-				# return RFC2317 compliant zone
110
-				return net.reverse_pointer
118
+				# RFC2317 compliant!
119
+				rfc2317Domain = "%s/%s.%s" % (parts[4 - net.prefixlen // 8 - 1], net.prefixlen, domain)
120
+				return rfc2317Domain
111 121
 		else:
112
-			# ipv6
113
-			# thefuck ipaddress lib... _the_ _fuck_
114
-			zoneParts = net.reverse_pointer.split(".")[-2 - net.prefixlen // 4:]
115
-
116
-			return ".".join(zoneParts)
122
+			## does not work with python3.4
123
+			## ipv6
124
+			## thefuck ipaddress lib... _the_ _fuck_
125
+			#zoneParts = net.reverse_pointer.split(".")[-2 - net.prefixlen // 4:]
126
+			#return ".".join(zoneParts)
127
+
128
+			parts = list(reversed(net.exploded.split("/")[0].replace(":", "")))[32 - net.prefixlen // 4:]
129
+			return ".".join(parts) + ".ip6.arpa."
117 130
 
118 131
 	def get_absolute_url(self):
119 132
 		return reverse("domains:reversezone-show", args=(self.pk,))

Loading…
Cancel
Save