Canonicalize CIDR: Difference between revisions
Content added Content deleted
(Add more examples.) |
m (→{{header|REXX}}: changed a comment, updated example nodes.) |
||
Line 434: | Line 434: | ||
parse arg a . /*obtain optional argument from the CL.*/ |
parse arg a . /*obtain optional argument from the CL.*/ |
||
if a=='' | a=="," then a= '87.70.141.1/22' , /*Not specified? Then use the defaults*/ |
if a=='' | a=="," then a= '87.70.141.1/22' , /*Not specified? Then use the defaults*/ |
||
' |
'36.18.154.103/12' , |
||
' |
'62.62.197.11/29' , |
||
' |
'67.137.119.181/4' , |
||
' |
'161.214.74.21/24' , |
||
' |
'184.232.176.184/18' |
||
'10.11.12.13/8' |
|||
do i=1 for words(a); z= word(a, i) /*process each IPv4 address in the list*/ |
do i=1 for words(a); z= word(a, i) /*process each IPv4 address in the list*/ |
||
Line 453: | Line 452: | ||
##= left(##, 32, 0) /*replace cropped bits with binary '0's*/ |
##= left(##, 32, 0) /*replace cropped bits with binary '0's*/ |
||
do j=8 by 8 for 4 /* [↓] parse the four nodes of address*/ |
do j=8 by 8 for 4 /* [↓] parse the four nodes of address*/ |
||
$= $ || . || b2d(substr(##, j-7, 8)) /*reconstitute decimal nodes.*/ |
$= $ || . || b2d(substr(##, j-7, 8)) /*reconstitute the decimal nodes. */ |
||
end /*j*/ /* [↑] and insert a dot between nodes.*/ |
end /*j*/ /* [↑] and insert a dot between nodes.*/ |
||
say /*introduce a blank line between IPv4's*/ |
say /*introduce a blank line between IPv4's*/ |
||
Line 469: | Line 468: | ||
canonicalized address: 87.70.140.0/22 |
canonicalized address: 87.70.140.0/22 |
||
original IPv4 address: |
original IPv4 address: 36.18.154.103/12 |
||
canonicalized address: |
canonicalized address: 36.16.0.0/12 |
||
original IPv4 address: |
original IPv4 address: 62.62.197.11/29 |
||
canonicalized address: |
canonicalized address: 62.62.197.8/29 |
||
original IPv4 address: |
original IPv4 address: 67.137.119.181/4 |
||
canonicalized address: |
canonicalized address: 64.0.0.0/4 |
||
original IPv4 address: |
original IPv4 address: 161.214.74.21/24 |
||
canonicalized address: |
canonicalized address: 161.214.74.0/24 |
||
original IPv4 address: |
original IPv4 address: 184.232.176.184/18 |
||
canonicalized address: |
canonicalized address: 184.232.128.0/18 |
||
original IPv4 address: 10.11.12.13/8 |
|||
canonicalized address: 10.0.0.0/8 |
|||
</pre> |
</pre> |
||