开发者

How to calculate available ip addresses in a given range with vbscript?

开发者 https://www.devze.com 2023-03-05 09:22 出处:网络
I have an ip range. 192.168.1.0/28 so ips are 192.168.1.1 192.168.1.2 . . . 192.168.1.13 192.168.1.14 Let\'s say some of these ips are being used. And this informat开发者_运维技巧ion is available t

I have an ip range. 192.168.1.0/28 so ips are

192.168.1.1
192.168.1.2
.
.
.
192.168.1.13
192.168.1.14

Let's say some of these ips are being used. And this informat开发者_运维技巧ion is available to me.

192.168.1.1
192.168.1.2

Now, I need to calculate all the available addresses left in the range given. Answer should be

192.168.1.3
192.168.1.4
.
.
192.168.1.13
192.168.1.14

How can I calculate this with vbscript?

I have used a very easy range for the sake of making the question simple but in real world I need to perform this operation on much larger subnets.

Thanks


After a few days of research. I figured out the script. Here's the answer

Dim strAllIP, strUsedIP, strAvailableIps
Dim ynum, xnum, counter, outercounter

ynum = 0
xnum = 0
counter = 0
outercounter = 0

strAllIP = Array("192.168.1.1","192.168.1.2","192.168.1.3", _
                 "192.168.1.4","192.168.1.5","192.168.1.6", _
                 "192.168.1.7","192.168.1.8","192.168.1.9", _
                 "192.168.1.10","192.168.1.11","192.168.1.12", _
                 "192.168.1.13", "192.168.1.14")

strUsedIP = Array("192.168.1.1","192.168.1.2")

For each i in strAllIP


  For each j in strUsedIP
  If i = j Then
  Exit For
  End if
  counter = counter + 1
  If counter - 1 = Ubound(strUsedIP) Then
  Match = True
  Exit for
  End if
  Next

  counter = 0
  If match = True Then
  Redim preserve newarray(outercounter)
  newarray(outercounter)= i
  outercounter = outercounter + 1
  End if
  Match = False

Next

strAvailableIps = join(newarray,chr(13))
msgbox strAvailableIps,0,"Available IPs"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号