| 
| 
| 
| #81979 - 2002-10-25 09:39 PM  TCP/IP Primer, Part III - IP Addresses and KiXtart |  
| Sealeopard   KiX Master
 
       
   Registered:  2001-04-25
 Posts: 11165
 Loc:  Boston, MA, USA
 | 
TCP/IP Primer, Part III - IP Addresses and KiXtart
 
 
 KiXtart has the ability to return the IP addresses of a computer with the IPADDRESSx macro.  The subnet mask of a specific adapter can be retrieved from either ENUMIPINFO(), the registry, through WMI, or using command-line utilities like IPCONFIG.
 Recommended Freeware Subnet Calculator
 Advanced IP Address Calculator for FamaTech, downloadable at http://www.famatech.com/download/default.html
 
 UDFs involving IP addresses
 The following UDFs handle IP address functions:
 
 
 BinaryIP is a UDF that converts the octet version of an IP address (e.g. 192.168.1.3) into it's equivalent binary format (e.g. 11000000101010000000000100000011).  This IP address can be a network ID, host ID, or subnet mask, as long as it is four octets.
 
 Subnet and IsInSubnet both check whether a given IP address is part of a subnet as defined by it's network ID and subnet mask.
 
 IsInIPRange is a slightly expanded version of Subnet and IsInSubnet since it accepts an array of subnets  (NetworkID/SubnetMask).  It will check whether a given IP address is part of any of the provided subnets.  Example code would look like this:
 Code:
 
 
$ipaddress='10.10.0.5'
 $iparray[0]='10.10.0.0/24'
 $iparray[1]='192.168.0.0/255.255.255.224'
 $retcode = isiniprange($ipaddress,$iparray)
 
 
 
 In the example above the IP address 10.10.0.5 is being evaluated whether it is part of either the network 10.10.0.0/24 or network 192.168.0.0/255.255.255.224.  Please note that IsInIPRange accepts both the CIDR format /24 as well as the more traditional octet format 255.255.255.224 as subnet masks.
 
 IPMask and CalcLogicalSubnet perform a binary AND of two binary IP addresses, it could for example be used to calculate the network ID based on Host ID and Subnet mask since (HostID AND SubnetMask) = NetworkID.
 
 GetIPinfo will retrieve a computers IP address, subnet mask, and default gateway.
 
 Potential usesThe main use of the above mentioned UDFs would be to check whether an IP address is part of a subnet or a particular range of IP addresses as defined by it's network ID and subnet mask or other appropriate combinations.
 For example, only certain computers are to connect to a specific drive share based on their IP address.  One could then create an array of permitted IP addresses or address ranges and do the following:
 Code:
 
 
$ipaddress=@IPADDRESS0
 $iparray[0]='192.168.1.0/24'
 $iparray[1]='192.168.2.0/255.255.255.224'
 $iparray[3]='192.168.3.0/255.255.255.0'
 if isiniprange($ipaddress,$iparray)
 use X: '\\server\share'
 endif
 
 
 This would allow IP addresses in the ranges 192.168.1.1-192.168.1.254, 192.168.2.1-192.168.2.30, and 192.168.3.1-192.168.3.254 to connect drive letter X: to share \\server\share.
 
 TCP/IP Primer, Part III - IP Addresses and KiXtart
 
 
 
 
 Edited by sealeopard (2004-03-11 03:46 PM)
 
_________________________There are two types of vessels, submarines and targets.
 |  
| Top |  |  |  |  
 Moderator:  Jochen, Radimus, Glenn Barnas, Allen, Arend_, ShaneEP, Mart
 
 | 
| 
 
| 0 registered
and 360 anonymous users online. 
 | 
 |  |