BLOG     |     FORUM
Your first integrated script

Tutorial : Your first integrated script


Integrated scripts allows you to extend the functionality of Unsniff by attaching custom scripts to various user interface elements. In this tutorial we will write a simple script and attach it to a menu item. You will also learn to work with the current selection contexts and the script console.

Please have the Unsniff Scripting Guide handy for reference to all objects, their methods and properties.



Task : Print a description of each selected packet (Packet.Description) to the Script Console
 

There are three parts to this task
 For this tutorial we shall use the VBScript language as this is available on all Windows 2000/XP systems.

Step 1. Write the script

Write the following VBScript script and save it to a file (eg: myprint.vbs)

VBScript code
' ---------------------------------

' Get access to the script console

' ---------------------------------

Dim Con
Set Con = CurrentDocument.Console
Con.TextColor = “#55EE33”

 

Con.WriteLine “Packet Printer Demo”
Con.WriteLine “-------------------“

 

Set SelPacketList = CurrentDocument.SelectedPackets

For Each Packet In SelPacketList

      Con.WriteLine     Packet.Description

Next


Step 2: Integrate the script into Unsniff

First we have to decide where in Unsniff we want to attach our script. In this case, it is pretty easy to figure that out. Since we want to print the description of all selected packets, we want to attach the script to the “Packet Sheet context menu”. Lets see how we can do that !

Open the User Scripts Manager via Tools à User Scripts This opens the “Manage User Scripts” dialog.
Script Integration
 

 
Click on the “New” button on the top-right corner of the dialog. This opens the “Script Details Dialog” which allows you to create a new menu item and attach your script to it. The “Script Details” Dialog is shown below. Use this dialog to enter the following details shown in the table.
Integration
 
 
NameA short name for the script.
ContextSelect where you want to attach your scripts.

In this example; we want to attach our script to the “Packet Sheet context menu”
Menu TagA menu tag identifies how your script will be merged with the existing menu. You can use a “\” (backslash) character to create nested menus. 

In this example; we want to call our menu item “Print Description”  and we do not want any nested menus.
Description   
Optional description
Script file   Click the browse button to select your script file you created in Step 1 (myscript.vbs)

Click OK – then restart Unsniff to complete your integration.

Step 3 : Executing our script

Open a capture file, select a few packets, and right click on the Packets Sheet. The figure below shows a your script attached to the Packets sheet context menu.

Integrated Scripts
 

Right click and select the menu item labelled “Print Description”. This will execute your script and output results to the Script Console window. Now the Script Console window will show the desired analysis output.

 Script Integration

 
Any errors will be sent to the log window. If you cannot see the log window, select View->Log Window from the main menu..