We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 33954e7 commit 285fe5cCopy full SHA for 285fe5c
1 file changed
iptools/ipv4.py
@@ -285,6 +285,10 @@ def validate_netmask(s):
285
True
286
>>> validate_netmask('128.0.0.1')
287
False
288
+ >>> validate_netmask('1.255.255.0')
289
+ False
290
+ >>> validate_netmask('0.255.255.0')
291
292
293
294
:param s: String to validate as a dotted-quad notation netmask.
@@ -293,7 +297,8 @@ def validate_netmask(s):
297
:raises: TypeError
298
"""
295
299
if validate_ip(s):
296
- mask = bin(ip2network(s))[2:]
300
+ # Convert to binary string, strip '0b' prefix, 0 pad to 32 bits
301
+ mask = bin(ip2network(s))[2:].zfill(32)
302
# all left most bits must be 1, all right most must be 0
303
seen0 = False
304
for c in mask:
0 commit comments