|
|
|
| 26 April 2002 | CalcLogicalSubnet() |
| Author | Howard A. Bullock |
| Action | This function returns the logical subnet ID when given an IP-Address and Subnet mask. |
| Syntax | CalcLogicalSubnet (IP, SNmask) |
| Parameters | |
| Remarks | This 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(). |
| Returns | The logical subnet where a computer resides for a given IP address and subnet mask. |
| Dependencies | None. |
| 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 -
|
|
|
|