I have recently spent some time trying to figure out how to write  a function that would take in an IP range, and return all the IPs  in between. I have found quite a few examples, but all of those, were actually getting the IP range within a full subnet. i.e:  what I wanted, was a function that would give me the IPs between a range of IPs like the following: –

Since I was scripting with Kixtart, I wrote the function in that language, though, if you know your way around VB, this could fairly easily be translated over.

The function I wrote is dependent on a UDF from the Kixtart UDF collection (find the EnumIPRange Function)

The following is the code for the function wrapper that would get the IP range:

; Author: Georges Khairallah (gkhairallah@gmail.com)
; Description: Function that allows the input of an IP range and returns the list of IPs in an array
; Dependencies: UDF: EnumIPRange from http://Kixtart.org/UDF
; Returns: Array with the IP listing
; Examples:
; $Network = ""
; $Mask = ""
; $StartIP = ""
; $EndIP = ""
; $IPList = GetIPListing($Network,$Mask,$StartIP,$EndIP)
; For Each $i in $IPList
; $i ?
; Next

Function GetIPListing($Network,$Mask,$StartIP,$EndIP)
Dim $sipIX, $eipIX, $i
Dim $aIPRange [2032]
$IPRange = EnumIPRange($Network, $Mask)
$sipIX = AScan($IPRange,$StartIP)
$eipIX = AScan($IPRange,$EndIP)
$IXCounter = 0
For $i = $sipIX to $eipIX
$aIPRange[$IXCounter] = $IPRange[$i]
$IXCounter = $IXCounter + 1
ReDim Preserve $aIPRange[$IXCounter - 1]
$GetIPListing = $aIPRange

Hope you find this bit of code useful.

Print Friendly, PDF & Email
Subscribe By Email for Updates.