WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

UDF - UDS Library
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

IsIpInRange

 Keywords:  Ip Address IPAddress Range CIDR Notation Network Address Convert Number

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Accepts an IP Address and a network
;;; CIDR range. Returns true if the
;;; IP Address is part of the CIDR
;;; range.
#DefineFunction IsIpInRange(_Ip, _Net)

   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ;; Needs parameter checking!
   ; Convert Ip Address to number
   nIp = 0
   For i = 1 To 4
      nIp = nIp + (ItemExtract(i, _Ip, ".") << (8*(4-i)))
   Next

   ; Get the CIDR notation network address part.
   nNet = 0
   lNet = ItemExtract(1, _Net, "/")
   For i = 1 To 4
      nNet = nNet + (ItemExtract(i, lNet, ".") << (8*(4-i)))
   Next

   ; Create a mask from the CIDR range part.
   Bits  = ItemExtract(2, _Net, "/")
   nMask = (~0)<<(32-Bits)
   Return (nIp&nMask) == (nNet&nMask)
#EndFunction

 ;Test
 bInRange = IsIpInRange("10.20.25.11", "10.228.24.0/23")

Article ID:   W18334
Filename:   IsIpInRange.txt
File Created: 2014:03:19:10:12:18
Last Updated: 2014:03:19:10:12:18