-
Oct 17th, 2014, 11:21 AM
#1
Thread Starter
New Member
IP Range expansion
Hello, I need a vbscript that will parse through a text file where every new line is either an ip address or ip range (ex 10.10.10.10 or 11.11.11.11-13)
I need a script that will parse through the text file and find the ip ranges. When it finds an IP range it will expand it (ex 11.11.11.11-13 = 11.11.11.11 11.11.11.11.12 11.11.11.13 but with returns instead of blank spaces) once it expands that IP range into single ip addresses, it should delete the range and pipe it into a new file. I need to expand and remove the ip ranges so i can audit all the ip addresses.
current txt file
8.8.8.8
8.8.8.9
8.8.8.11-13
9.8.9.9
9.8.9.10-11
this is what i would like it to look like vbscript output txt file
8.8.8.8
8.8.8.9
8.8.8.11
8.8.8.12
8.8.8.13
9.8.9.9
9.8.9.10
9.8.9.11
-
Oct 24th, 2014, 01:36 PM
#2
Re: IP Range expansion
For this example I'm just using arrays to make it easy. I'll leave it to you to figure out how to pull and save your values.
Code:
Option Explicit
dim arrInput(4)
dim arrOutput()
dim i
dim a
dim display
arrInput(0) = "8.8.8.8"
arrInput(1) = "8.8.8.9"
arrInput(2) = "8.8.8.11-13"
arrInput(3) = "9.8.9.9"
arrInput(4) = "9.8.9.10-11"
for i = 0 to UBound(arrInput)
If InStr(arrInput(i), "-") Then
GetNewList arrInput(i)
Else
Redim Preserve arrOutput(a)
arrOutput(a) = arrInput(i)
a = a + 1
End If
next
display = "Input Values " & vbcrlf & Join(arrInput, vbCrLf)
display = display & vbcrlf & vbcrlf & "Output Values" & vbCrLf
display = display & Join(arrOutput, vbCrLf)
msgbox display
Public Sub GetNewList(byval range)
dim base
dim arrTemp
dim lb, ub
dim x
' Store the constant part of the ip range. ex - 8.8.8.
base = Left(range, InStrRev(range, "."))
' Strip the constant part so we know the range to work with
range = Replace(range, base, "")
' Get the low and high numbers for the range
arrTemp = Split(range, "-")
lb = CInt(LBound(arrTemp))
ub = CInt(UBound(arrTemp))
' Loop and add the Range to the Output array
For x = arrtemp(lb) to arrtemp(ub)
Redim Preserve arrOutput(a)
arrOutput(a) = base & x
a = a + 1
next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|