scripting@wanadoo.nl




CalcLogicalSubnet()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
26 April 2002 CalcLogicalSubnet()
AuthorHoward A. Bullock
Action This function returns the logical subnet ID when given an IP-Address and Subnet mask.
SyntaxCalcLogicalSubnet (IP, SNmask) 
Parameters
  • $IP (Required / String) IP address: Can be padded with spaces as from @IPAddressX or without as generated by ENUMIPINFO.
  • $SNmask (Required / String) A valid subnet mask. 
  • RemarksThis UDF does not find or return the required subnet mask. Since EnumIPinfo() does not return values for many computers, I have written another UDF to insure that the proper data exists to use this function. See GetIPinfo()
    ReturnsThe logical subnet where a computer resides for a given IP address and subnet mask. 
    DependenciesNone. 
    Examples
    $IP = "192.163.0.  4"
    $SNmask = "255.255.255.128"
    $LogicalSubnet = CalcLogicalSubnet ($IP, $SNmask)
    call "$LogicalSubnet.kix" ;call "192.163.0.0.kix"
    
    $IP = "192.163.0.150"
    $SNmask = "255.255.255.128"
    $LogicalSubnet = CalcLogicalSubnet ($IP, $SNmask)
    call "$LogicalSubnet.kix" ;call "192.163.0.128.kix"
    
     
    Source
    FUNCTION CalcLogicalSubnet ($ip, $snmask)
      ;
      ; Version 2.0
      ; This function calculates the logical subnet for a given IP address and subnet mask.
      ; The $IP parameter can be padded with spaces as from @IPADDRESS0 or without
      ; as from EnumIPinfo().
      ;
      ; Sets two exit codes that are passed to @error
      ; 1 = Improperly formatted IP address
      ; 2 = Octet out range (0-255)
      ;
      DIM $ip, $snmask
      DIM $i         ;Counter for looping through 4 octets of the IP and subnet mask
      DIM $arrayip   ;Holds the string representation of the IP address octets.
      DIM $arraysn   ;Holds the string representation of the subnet mask octet.
      DIM $subnet    ;Holds the string that becomes the logical subnet.
      DIM $x, $y     ;Holds value of IP and SNmask octet.
    
      $arrayip = Split($ip, ".")
      $arraysn = Split($snmask, ".")
    
      IF UBound($arrayip) = 3 AND UBound($arraysn) = 3
        FOR $i = 0 TO 3
          $x = Val(Ltrim($arrayip[$i]))
          $y = Val(Ltrim($arraysn[$i]))
          IF ($x >= 0) AND ($x < 256) AND ($y >= 0) AND ($y < 256)
            $subnet = ""+$subnet+($x & $y)+"."
          ELSE
            EXIT(2)
          ENDIF
        NEXT
        $calclogicalsubnet = Substr($subnet, 1, Len($subnet)-1)
        EXIT(0)
      ELSE
        EXIT(1)
      ENDIF
    ENDFUNCTION ; - CalcLogicalSubnet -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter