The scripting interface consists of a single top-level object called Unsniff.Database. This object represents a single capture file stored in the Unsniff ( *.usnf ) format. Your task is to get hold of the “Unsniff.Database” object and work your way through the other objects. If you are writing an integrated script – you can additionally access the currently open document, various selection contexts, and the scripting console. See Section 4 for more details on integrated scripts.
The following picture shows how the Object Model is organized. Only object names and their relationships are shown here.
The Unsniff Scripting Object Model is a hierarchical structure. Only one top-level object ”Unsniff.Database is publicly creatable via the Prog ID Unsniff.Database”. All other objects are accessed via methods and properties of already created objects.
To create the root object:
VBScript
Set MyDB = CreateObject (“Unsniff.Database”)
Ruby
MyDB = Win32OLE.new (“Unsniff.Database”)
Let us consider a simple example. In this example, we will write a script to print the description of each packet in a given Unsniff capture file.This example will illustrate the following concepts.
Example: Print the description of each packet in a given capture file.
VBScript
' ----------------------- ' Check usage & arguments ' ----------------------- if WScript.Arguments.Count <> 1 then WScript.Echo "Usage: prpidx <filename>" WScript.Quit end if ArgFile = WScript.Arguments.Item(0) ‘ ---------------------------------------- ‘ Open the file & navigate to packet index ‘ ---------------------------------------- Set UnsniffDB = CreateObject("Unsniff.Database") UnsniffDB.Open(ArgFile) Set PacketStore = UnsniffDB.PacketIndex For Each Packet In PacketStore WScript.Echo Packet.Description Next UnsniffDB.Close( )
Ruby
require 'win32ole' USAGE = "prpidx <capture-filename>" # # function: print the description # def printPacket(packet) $stdout << packet.Description << “\n” end # # check arguments # if ARGV.length != 1 puts USAGE exit 1 end UnsniffDB = WIN32OLE.new("Unsniff.Database") UnsniffDB.Open(ARGV[0]) Count = UnsniffDB.PacketCount PacketStore PacketStore = UnsniffDB['PacketIndex'] (0..Count- (0..Count-1).each{ |idx| printPacket(PacketStore.Item(idx)) } UnsniffDB.Close()