An atempt to Convert CIDR to NETMASK

Author Message
dpallone

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 4/26/2011
  • Location: San Antonio, TX
  • Status: offline
An atempt to Convert CIDR to NETMASK Friday, May 13, 2011 2:05 AM (permalink)
0
You just need to pass the CIDR number to the SUB. 
I recieved the data in this format <IP ADDRESS>/<CIDR> so I needed to filter and rebuild with split and filter. Have a look and let me know what you think.
 
 sub Action_Mask
 j = 0
 for j = 0 to lineRule - 1
  redim arrText(ubound(arrOUTBound))
  arrText(j) = arrBound(5,j)
  strText = arrText(j)   outputArray = filter(array(strText),"/")
  if join(outputArray) <> "" then 
   netArray = split(strText ,"/")
   for each w in netArray
    if len(w) = 2 then
     CIDR2Mask(w)
    else
     strIP = w & "/"
    end if
    strIP = strIP  & strPassMask
    strPassMask = EMPTY
   next
   arrBound(5,j) = strIP
   strIP = empty
  else 
  end if
 if strText = "" then 
  strText = "*"
 end if
 next
END SUB   SUB CIDR2Mask(strPassCIDR) 
 DIM full_octets, partial_octet, strMask 
 DIM intCalc, intCIDR, i 
  
 intCIDR = strPassCIDR 
 ' Calculate the Full and Partial Octets 
 full_octets = intCIDR \ 8 
 partial_octet = intCIDR MOD 8 
 strMask = "255" 
 i = 0 
  
 for i = 0 to 4 
  if i < full_octets then 
   strMask = strMask & ".255" 
   else if i = full_octets then 
    intCalc = (256 - 2^(8 - partial_octet)) 
    strMask = strMask & "." & intCalc 
   else 
    strMask = strMask & ".0" 
   end if 
  end if 
  i = i + 1 
 NEXT 
 strPassMask = strMask 
END SUB 

INPUT DATA EXAMPLE: 172.16.20.0/22
OUTPUT DATA EXAMPLE: 172.16.20.0/255.255.252.0
 
I converted this C# script from here:
http://code.google.com/p/mats-tools/source/browse/trunk/cidr2mask.sh?spec=svn2&r=2
I don't know who wrote the origional code but Many Props to you for doing so.
 
Dan Pallone II  
"I became insane, with long intervals of horrible sanity."
Edgar Allan Poe 
<message edited by dpallone on Friday, May 13, 2011 2:41 AM>
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9