Scripting Object Model

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.

Object Model Diagram

The following picture shows how the Object Model is organized. Only object names and their relationships are shown here.

Object Creation

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”)
  

A simple example

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.

  • The structure of a typical script application
  • How the root object is created and accessed
  • How you can navigate to the other objects

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()
unsniff/scriptobjmod.txt · Last modified: 2014/09/11 23:23 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki