' ' pktcopy - Copies given packets from file-1 to file-2 ' ' ----------------------- ' Check usage & arguments ' ----------------------- Set Sout = WScript.StdOut if WScript.Arguments.Count <> 3 then Sout.WriteLine "Usage: pktcopy <packets-csv> <from-filename> <to-filename>" WScript.Quit end if PacketsCSV = WScript.Arguments.Item(0) FromFile = WScript.Arguments.Item(1) ToFile = WScript.Arguments.Item(2) Set FromDB = CreateObject("Unsniff.Database") Set ToDB = CreateObject("Unsniff.Database") Set FSO = CreateObject("Scripting.FileSystemObject") FromDB.Open(FromFile) If FSO.FileExists (ToFile) Then ToDB.Open(ToFile) Else ToDB.New(ToFile) End If Dim PktIdxArray PktIdxArray = Split(PacketsCSV, ",", -1, 1) ' ' Save the specified packets to the target DB ' Set Packets = FromDB.PacketIndex For I = 0 To UBound ( PktIdxArray) Set Packet = Packets(I) ToDB.AddPacket (Packet) Next FromDB.Close() ToDB.Save() ToDB.Close() Sout.WriteLine "Saved in " & ToFile Function Tokenize(byVal TokenString, byRef TokenSeparators()) Dim NumWords, a() NumWords = 0 Dim NumSeps NumSeps = UBound(TokenSeparators) Do Dim SepIndex, SepPosition SepPosition = 0 SepIndex = -1 for i = 0 to NumSeps-1 ' Find location of separator in the string Dim pos pos = InStr(TokenString, TokenSeparators(i)) ' Is the separator present, and is it closest to the beginning of the string? If pos > 0 and ( (SepPosition = 0) or (pos < SepPosition) ) Then SepPosition = pos SepIndex = i End If Next ' Did we find any separators? If SepIndex < 0 Then ' None found - so the token is the remaining string redim preserve a(NumWords+1) a(NumWords) = TokenString Else ' Found a token - pull out the substring Dim substr substr = Trim(Left(TokenString, SepPosition-1)) ' Add the token to the list redim preserve a(NumWords+1) a(NumWords) = substr ' Cutoff the token we just found Dim TrimPosition TrimPosition = SepPosition+Len(TokenSeparators(SepIndex)) TokenString = Trim(Mid(TokenString, TrimPosition)) End If NumWords = NumWords + 1 loop while (SepIndex >= 0) Tokenize = a End Function