/* Simple subnet calculator By Casey Halverson wwww.maokhian.com Feel free to do what you please with this piece of code! */ a=arg(1) ip=word(a,1) subnet=word(a,2) if a="" then do;say "subnet.rexx [ip] [subnet]";exit;end /* convert octets into spaced out instead of .'ed out */ ip=translate(ip," ",".") subnet=translate(subnet," ",".") /* convert each decimal octet into a hex number then into a binary number */ ip.1=x2b(d2x(word(ip,1))) ip.2=x2b(d2x(word(ip,2))) ip.3=x2b(d2x(word(ip,3))) ip.4=x2b(d2x(word(ip,4))) sub.1=x2b(d2x(word(subnet,1))) sub.2=x2b(d2x(word(subnet,2))) sub.3=x2b(d2x(word(subnet,3))) sub.4=x2b(d2x(word(subnet,4))) /* Combined the binary sections into one big super binary number (32bits) */ do i=1 to 4 if length(sub.i)=1 then sub.i="0000000"||sub.i if length(sub.i)=2 then sub.i="000000"||sub.i if length(sub.i)=3 then sub.i="00000"||sub.i if length(sub.i)=4 then sub.i="0000"||sub.i if length(sub.i)=5 then sub.i="000"||sub.i if length(sub.i)=6 then sub.i="00"||sub.i if length(sub.i)=7 then sub.i="0"||sub.i end do i=1 to 4 if length(ip.i)=1 then ip.i="0000000"||ip.i if length(ip.i)=2 then ip.i="000000"||ip.i if length(ip.i)=3 then ip.i="00000"||ip.i if length(ip.i)=4 then ip.i="0000"||ip.i if length(ip.i)=5 then ip.i="000"||ip.i if length(ip.i)=6 then ip.i="00"||ip.i if length(ip.i)=7 then ip.i="0"||ip.i end superip=ip.1||ip.2||ip.3||ip.4 supersub=sub.1||sub.2||sub.3||sub.4 network=bitand(superip,supersub) net.1=substr(network,1,8) net.2=substr(network,9,8) net.3=substr(network,17,8) net.4=substr(network,25,8) say "IP Address : "ip net.1=b2x(net.1) net.2=b2x(net.2) net.3=b2x(net.3) net.4=b2x(net.4) say "Network Address : "x2d(net.1)"."x2d(net.2)"."x2d(net.3)"."x2d(net.4)