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