Canonicalize CIDR: Difference between revisions

→‎{{header|Python}}: trim whitespace
(→‎{{header|Perl}}: Add comments, remove some extraneous parens.)
(→‎{{header|Python}}: trim whitespace)
Line 37:
=={{header|Python}}==
{{trans|Perl}}
<lang python>#!/usr/bin/env python
#!/usr/bin/env python
# canonicalize a CIDR block specification:
# make sure none of the host bits are set
Line 62 ⟶ 61:
canon_dotted = inet_ntoa(pack('!I',
(canon_numeric))) # and then to dotted-decimal
print(f'{canon_dotted}/{size}') # output result</lang>
</lang>
{{Out}}
<pre>$ canonicalize_cidr.py 87.70.141.1/22
1,481

edits