Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
39
Task/Parse-an-IP-Address/REXX/parse-an-ip-address-1.rexx
Normal file
39
Task/Parse-an-IP-Address/REXX/parse-an-ip-address-1.rexx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/*REXX program to parse an IP address into ──► IPv4 or IPv6 format, port*/
|
||||
say center('input IP address' ,30),
|
||||
center('hex IP address' ,32),
|
||||
center('decimal IP address' ,39) 'space port'
|
||||
_='─'
|
||||
say copies(_,30) copies(_,32) copies(_,39) copies(_,5) copies(_,5)
|
||||
call IP_parse 127.0.0.1 /*this IP doesn't need quotes. */
|
||||
call IP_parse '127.0.0.1:80'
|
||||
call IP_parse '::1'
|
||||
call IP_parse '[::1]:80'
|
||||
call IP_parse '2605:2700:0:3::4713:93e3'
|
||||
call IP_parse '[2605:2700:0:3::4713:93e3]:80'
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────IP_parse subroutine─────────────────*/
|
||||
IP_parse: procedure; parse arg a .; hx=; @.=; numeric digits 50
|
||||
dot=pos('.',a)\==0 /*see if there is a dot present. */
|
||||
|
||||
if dot then do; parse var a @.1 '.' @.2 "." @.3 '.' @.4 ":" port
|
||||
do j=1 for 4; hx=hx || d2x(@.j,2)
|
||||
end /*j*/
|
||||
end /*if dot*/
|
||||
else do; parse var a pureA ']:' port
|
||||
_=space(translate(pureA,,'[]'),0) /*remove brackets*/
|
||||
parse var _ x '::' y
|
||||
do L=1 until x=='' /*get left side.*/
|
||||
parse var x @.L ':' x
|
||||
end /*L*/
|
||||
y=reverse(y)
|
||||
do r=8 by -1 /*get right side.*/
|
||||
parse var y z ':' y; if z=='' then leave
|
||||
@.r=reverse(z)
|
||||
end /*r*/
|
||||
|
||||
do k=1 for 8; hx=hx || right(word(@.k 0, 1), 4, 0)
|
||||
end /*k*/
|
||||
end /*else dot*/
|
||||
|
||||
say left(a,30) right(hx,32) right(x2d(hx),39) ' IPv'||(6-2*dot) right(port,5)
|
||||
return
|
||||
83
Task/Parse-an-IP-Address/REXX/parse-an-ip-address-2.rexx
Normal file
83
Task/Parse-an-IP-Address/REXX/parse-an-ip-address-2.rexx
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/* REXX ***************************************************************
|
||||
* 27.05.2013 Walter Pachl
|
||||
**********************************************************************/
|
||||
Numeric Digits 100
|
||||
say center('input IP address' ,30),
|
||||
center('hex IP address' ,32),
|
||||
center('decimal IP address' ,39) 'space port'
|
||||
|
||||
say copies(_,30) copies(_,32) copies(_,39) copies(_,5) copies(_,5) /*hdr*/
|
||||
call expand '127.0.0.1'
|
||||
call expand '127.0.0.1:80'
|
||||
call expand '::1'
|
||||
call expand '[::1]:80'
|
||||
call expand '2605:2700:0:3::4713:93e3'
|
||||
call expand '[2605:2700:0:3::4713:93e3]:80'
|
||||
Say ' '
|
||||
Say 'The following 2 are the same'
|
||||
Call expand '2001:0db8:0:0:0:0:1428:57ab'
|
||||
Call expand '2001:db8::1428:57ab'
|
||||
Say ' '
|
||||
Say 'The following 3 are all the same'
|
||||
Call expand '2001:0db8:0:0:8d3:0:0:0'
|
||||
Call expand '2001:db8:0:0:8d3::'
|
||||
Call expand '2001:db8::8d3:0:0:0'
|
||||
Exit
|
||||
|
||||
expand: Procedure
|
||||
Parse Arg s
|
||||
If pos('.',s)>0 Then
|
||||
Parse Value expand_ip4(s) With exp space port
|
||||
Else
|
||||
Parse Value expand_ip6(s) With exp space port
|
||||
Say left(s,30) right(exp,32) right(x2d(exp),39) right(space,5) right(port,5)
|
||||
Return
|
||||
|
||||
expand_ip4: Procedure
|
||||
Parse Arg s
|
||||
If pos(':',s)>0 Then
|
||||
Parse Var s s ':' port
|
||||
Else
|
||||
port=''
|
||||
Do i=1 To 4
|
||||
Parse Var s a.i '.' s
|
||||
End
|
||||
res=''
|
||||
Do i=1 To 4
|
||||
res=res||d2x(a.i,2)
|
||||
End
|
||||
Return res 'IPv4' port
|
||||
|
||||
expand_ip6: Procedure
|
||||
/**********************************************************************
|
||||
* Note: Doublecolon ('::') requires the inclusion of as many 0000
|
||||
* tokens as necessary to result in 8 tokens
|
||||
**********************************************************************/
|
||||
Parse Arg s
|
||||
If pos(']:',s)>0 Then
|
||||
Parse Var s '[' s ']:' port
|
||||
Else
|
||||
port=''
|
||||
sc=s
|
||||
ii=0
|
||||
Do i=1 To 8 While s<>''
|
||||
Parse Var s x.i ':' s
|
||||
If left(s,1)=':' Then Do
|
||||
ii=i
|
||||
s=substr(s,2)
|
||||
End
|
||||
End
|
||||
n=i-1
|
||||
ol=''
|
||||
o2=''
|
||||
Do i=1 To n
|
||||
ol=ol||right(x.i,4,'0')
|
||||
o2=o2||right(x.i,4,'0')
|
||||
If i=ii Then Do
|
||||
ol=ol||'----'
|
||||
Do j=1 To 8-n
|
||||
o2=o2||'0000'
|
||||
End
|
||||
End
|
||||
End
|
||||
Return o2 'IPv6' port
|
||||
Loading…
Add table
Add a link
Reference in a new issue