From 623bf5a9a12bc950f1617fcfe844e7e062b16a3d Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 2 Jan 2016 22:59:10 -0500 Subject: [PATCH] Fix construction of packed CIDR mask from binary representation. --- earwigbot/commands/cidr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/earwigbot/commands/cidr.py b/earwigbot/commands/cidr.py index 2c30bfd..6b832fa 100644 --- a/earwigbot/commands/cidr.py +++ b/earwigbot/commands/cidr.py @@ -111,9 +111,11 @@ class CIDR(Command): break mask = bin_ips[0][:size].ljust(len(bin_ips[0]), "0") + packed = "".join( + chr(int(mask[i:i + 8], 2)) for i in xrange(0, len(mask), 8)) return _Range( family, - socket.inet_ntop(family, int(mask, 2)) + "/" + str(size), + socket.inet_ntop(family, packed) + "/" + str(size), size, self._format_count(2 ** (len(bin_ips[0]) - size)))