' ' ctrltrap - start, stop, and control the unbrowse trap ' passive receiver ' ' Usage: cscript ctrltrap.vbs ' trapdatabase = The VOTRP file where traps will be stored ' maxtraps = Stops after these many traps are captured ' ' -------------------------------------------------- ' Check usage & arguments ' -------------------------------------------------- Set Sout = WScript.StdOut If WScript.Arguments.Count <> 2 Then Sout.WriteLine "Usage: ctrltrap " WScript.Quit End If TrapDBFile = WScript.Arguments.Item(0) MaxTraps = WScript.Arguments.Item(1) ' -------------------------------------------------- ' Create the trap server ' -------------------------------------------------- Set TrapMgr = WScript.CreateObject("UnbrowseSNMP.TrapReceiver","OnTrap_") Sout.WriteLine "Loaded the Unbrowse SNMP Trap Server" ' -------------------------------------------------- ' Set some parameters ' -------------------------------------------------- TrapMgr.UsePromiscuousMode = True TrapMgr.PreferRawOverPcap = True ' -------------------------------------------------- ' Open a new database - you can save this later ' -------------------------------------------------- TrapMgr.NewDatabase ' -------------------------------------------------- ' Start the passive trap receiver ' -------------------------------------------------- Sout.WriteLine "Starting .." TrapMgr.Start Sout.WriteLine "Listening for traps .." ' ------------------------------------------------------ ' Enter into an loop, processing traps ' Here were stopping after a few traps for demo purposes ' ------------------------------------------------------ Sout.WriteLine "Dumping traps as they are received .. (Ctrl+C) to quit" TrapCount = 0 TrapsLeft = MaxTraps Do While TrapsLeft > 0 WScript.Sleep 100 TrapsLeft = MaxTraps - TrapCount Loop ' -------------------------------------------------- ' Stop the trap receiver ' -------------------------------------------------- Sout.WriteLine "Stopping the trap receiver" TrapMgr.Stop ' -------------------------------------------------- ' Save contents into the database given by user ' -------------------------------------------------- Sout.WriteLine "Saving to " & TrapDBFile TrapMgr.SaveAs TrapDBFile TrapMgr = Nil Sout.WriteLine "Done" WScript.Quit 0 ' --------------------------------------------------- ' OnNewTrap : Event handler ' When you get a new trap, do your thing ' --------------------------------------------------- Sub OnTrap_TNF_NewTrap (Id, OneTrap) PrintTrap(OneTrap) '-------------------------- ' After a few traps quit '-------------------------- TrapCount = TrapCount+1 End Sub ' --------------------------------------------------- ' PrintTrap : Subroutine ' Dumps almost all trap information onto screen ' --------------------------------------------------- Sub PrintTrap (OneTrap) ' -------------------------- ' Print all trap information ' -------------------------- Sout.WriteLine " ------------------------------------------" Sout.WriteLine " Trap ID : " & OneTrap.ID Sout.WriteLine " OID : " & OneTrap.EffectiveTrapOID Sout.WriteLine " From Agent : " & OneTrap.AgentAddress Sout.WriteLine " To Manager : " & OneTrap.DestinationAddress Sout.WriteLine " Timestamp : " & OneTrap.TimestampLocal Sout.WriteLine " OID : " & OneTrap.EffectiveTrapOID Sout.WriteLine " User/Comm : " & OneTrap.UserCommunity Sout.WriteLine " Varbinds : " & OneTrap.VarbindCount ' -------------------------- ' Print all varbinds in trap ' -------------------------- Sout.WriteLine " --------- Varbind list ----------" For I = 0 To OneTrap.VarbindCount - 1 Set OneVar = OneTrap.GetVarbindByIdx(I) Sout.WriteLine vbTab & " " & I+1 & " ) " & OneVar.OID & " = " & OneVar.Value Next Sout.WriteLine vbCrLf End Sub