2

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 information 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

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
Onat
  • 771
  • 1
  • 11
  • 17
  • why VBScript? Are you writing this as an application or an web script? – Nate Koppenhaver May 10 '11 at 19:10
  • Not for web. I am writing scripts for SecureCRT, a terminal client. Until recently that is what you had to use so I learnt VBScript. It now supports python but I don't know much about it yet. – Onat May 10 '11 at 19:34

1 Answers1

0

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"
Onat
  • 771
  • 1
  • 11
  • 17
  • I am new to scripting so it may not be organized the best way but script does work. If anyone is able to edit and make it look better, feel free to do so. – Onat May 13 '11 at 15:59
  • "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." – Vijay May 16 '11 at 15:20