Network Analyzer
Public Member Functions | Public Attributes | List of all members
Sniffer Class Reference

Defines a Sniffer class. More...

Inheritance diagram for Sniffer:
Inheritance graph
[legend]
Collaboration diagram for Sniffer:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, tabs)
 The Sniffer class initializer. More...
 
def add_feedback (self, feedback_text)
 Appends feedback to user of current activity. More...
 
def add_table_entry (self, pkt)
 Function than takes fields from the packet and adds entries to a table. More...
 
def clear_table (self)
 Clears table network capture table entries. More...
 
def get_host_name (self, ip)
 Function that resolves given IP address to a host name. More...
 
def interface_selected (self)
 Sets selected interface (network card) More...
 
def open_pcap (self)
 Opens file dialog to select file to be opened within application (.pcap). More...
 
def plot_bar_chart (self)
 Creates Bar chart from loaded data from captures. More...
 
def plot_pie_chart (self)
 Creates Pie chart from loaded data from captures. More...
 
def populate_filter_options (self)
 Populates gathered data from database in a filter options dropdown field. More...
 
def save_pcap (self)
 Opens file dialog to select file to be saved OR creates new file with a capture (.pcap). More...
 
def set_filter (self)
 Sets current filter option within filter field. More...
 
def sniff_thread (self, a)
 Function that is run in a separate thread. More...
 
def start_sniff (self)
 Function that is activated when RUN button is pressed. More...
 
def statistics (self)
 Organizes captured data by frequency and presents to user in readable manner. More...
 
def stop_sniff (self)
 Function that stops network capture. More...
 
def stop_sniffing (self, a)
 Function that is used by Scapy sniff function. More...
 
def table_row_item_selected (self)
 On a row selected within capture table, displays details of a packet selected within details field. More...
 
def update_filter_options_table (self)
 Inserts NOT present item to database (filter options) More...
 

Public Attributes

 btn_clear
 Initializes clear button. More...
 
 btn_clear_text
 Sets filter button text. More...
 
 btn_graph
 Initializes clear button. More...
 
 btn_graph_text
 Sets clear button text. More...
 
 btn_offset
 Sets offset for buttons. More...
 
 btn_open
 Initializes open button. More...
 
 btn_open_text
 Sets open button text. More...
 
 btn_pie
 Initializes clear button. More...
 
 btn_pie_text
 Sets clear button text. More...
 
 btn_run
 Initializes run button. More...
 
 btn_run_text
 Sets run button text. More...
 
 btn_save
 Initializes save button. More...
 
 btn_save_text
 Sets save button text. More...
 
 btn_stop
 Initializes stop button. More...
 
 btn_stop_text
 Sets stop button text. More...
 
 details_field
 Initializes field for packets details. More...
 
 dropdown_if_selection
 Current interface selection default is None. More...
 
 dropdown_interfaces
 Initializes dropdown combo box for interfaces. More...
 
 feedback_field
 Initializes field for feedback text. More...
 
 filter_input_combobox
 Initializes dropdown combo box for filters. More...
 
 filter_option
 Initializes filter options to None. More...
 
 host_name_checkbox
 Checkbox that that allows host name mapping. More...
 
 interfaces
 Gets interfaces from underlying operating system. More...
 
 is_filter_wrong
 Initializes boolean for a filter option if it is wrong default is False. More...
 
 is_running
 Status of sniffer default is False. More...
 
 layout
 Creates layout that will be used for a tab. More...
 
 packets_count
 Initializes packets captired to None. More...
 
 progress_label
 Initializes label for amount of packets captured. More...
 
 raw_field
 Initializes field for raw text. More...
 
 sniffer_results
 Initializes variable for captured results from sniff function. More...
 
 sniffer_tab
 Creates tab that will be returned. More...
 
 sniffer_thread
 Initializes thread for a sniffer (sniff function runs in its own thread) More...
 
 source_ips
 variable that stores source ips for statistics More...
 
 table
 Creates table for network capture results. More...
 

Detailed Description

Defines a Sniffer class.

Description

The Sniffer class is responsible for all components that is capable to capture network traffic and displaying result to user. Within application data can be filtered by type. Capture files can be saved and opened within application.

Libraries/Modules

Author(s)

Copyright (c) 2022 by Erlandas Bacauskas is licensed under CC BY-NC-SA 4.0. To view copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  tabs 
)

The Sniffer class initializer.

Returns
Tab for a Sniffer initialized with components

Member Function Documentation

◆ add_feedback()

def add_feedback (   self,
  feedback_text 
)

Appends feedback to user of current activity.

Parameters
feedback_textString that will be displayed within feedback field

◆ add_table_entry()

def add_table_entry (   self,
  pkt 
)

Function than takes fields from the packet and adds entries to a table.

  • Assigns packet type by analyzing numeric value of a packet
  • If IP packet takes needed fields for IP packet
  • Adds entry to table
  • Terminates function
  • Updates packet count
  • If ARP packet takes needed fields for ARP packet
  • Adds entry to table
  • Terminates function
  • Updates packet count
  • If IPv6 packet takes needed fields for IPv6 packet
  • Adds entry to table
  • Terminates function
  • Updates packet count
Parameters
pktCaptured packet that is dissected

◆ clear_table()

def clear_table (   self)

Clears table network capture table entries.

Activated when clear button pressed.

  • If network capture is active:
  • Appends text to feedback field indicating of active network capture
  • Terminates function
  • If network capture is not active:
  • If table is empty terminates function
  • If NOT empty:
  • Erases details field sets to None
  • Appends feedback
  • Sets table row counts to 0 (erasing all entries)
  • Sets packet count to 0
  • Sets packet capture label to indicate that 0 packets captured

◆ get_host_name()

def get_host_name (   self,
  ip 
)

Function that resolves given IP address to a host name.

Parameters
ipIP address to resolve
Returns
Domain name or IP address if it couldn't resolve

◆ interface_selected()

def interface_selected (   self)

Sets selected interface (network card)

  • Displays feedback for user

◆ open_pcap()

def open_pcap (   self)

Opens file dialog to select file to be opened within application (.pcap).

  • Checks if network capture is NOT active
  • If active:
  • Adds feedback
  • Terminates function
  • If NOT active
  • Opens file dialog to select file
  • When file selected clears table entries

◆ plot_bar_chart()

def plot_bar_chart (   self)

Creates Bar chart from loaded data from captures.

◆ plot_pie_chart()

def plot_pie_chart (   self)

Creates Pie chart from loaded data from captures.

◆ populate_filter_options()

def populate_filter_options (   self)

Populates gathered data from database in a filter options dropdown field.

  • Initializes controller
  • Retrieves data (if any)
  • Adds each data item gathered

◆ save_pcap()

def save_pcap (   self)

Opens file dialog to select file to be saved OR creates new file with a capture (.pcap).

  • Checks if network capture is NOT active
  • If active:
  • Adds feedback
  • Terminates function
  • If NOT active
  • Opens file dialog to save file

◆ set_filter()

def set_filter (   self)

Sets current filter option within filter field.

Activated when set filter button is pressed.

  • Assigns filter value to variable
  • Adds feedback
  • Calls function to update database table with used filter option

◆ sniff_thread()

def sniff_thread (   self,
  a 
)

Function that is run in a separate thread.

Captures network packets.

  • Runs while sniff break is set to False
  • Assesses filter validity
  • If filter is invalid terminates function
  • If sniff break set to True:
  • Resets thread
  • Resets filter option to None
  • Terminates function

◆ start_sniff()

def start_sniff (   self)

Function that is activated when RUN button is pressed.

Starts network capture.

  • Checks if network capture is not active
  • If it is active adds entry to feedback field and function terminates
  • if NOT active:
  • Clears table that holds captured packets if any
  • Takes current interface from interfaces dropdown
  • Sets running to True
  • Sets sniff break to false
  • Initializes sniffer thread
  • Starts sniffer thread
  • Checks if filter provided is valid
  • If NOT valid:
  • Boolean set that indicates that filter is wrong
  • Filter is discarded and network capture is run without filter option
  • Resets filter to None
  • Adds feedback to user indicating a problem
  • If filter is valid or None starts network capture

◆ statistics()

def statistics (   self)

Organizes captured data by frequency and presents to user in readable manner.

◆ stop_sniff()

def stop_sniff (   self)

Function that stops network capture.

Activated when stop button pressed.

  • Adds feedback
  • Resets filter options
  • Sets running to False
  • Sets sniff break to True

◆ stop_sniffing()

def stop_sniffing (   self,
  a 
)

Function that is used by Scapy sniff function.

After each packet capture checks if sniffing still should be active.

◆ table_row_item_selected()

def table_row_item_selected (   self)

On a row selected within capture table, displays details of a packet selected within details field.

◆ update_filter_options_table()

def update_filter_options_table (   self)

Inserts NOT present item to database (filter options)

  • Checks if item is NOT present within database (no duplicates allowed)
  • If present returns
  • If not present inserts item to database
  • Adds item to filter dropdown box

Member Data Documentation

◆ btn_clear

btn_clear

Initializes clear button.

◆ btn_clear_text

btn_clear_text

Sets filter button text.

Initializes set filter button Sets clear button text

◆ btn_graph

btn_graph

Initializes clear button.

◆ btn_graph_text

btn_graph_text

Sets clear button text.

◆ btn_offset

btn_offset

Sets offset for buttons.

◆ btn_open

btn_open

Initializes open button.

◆ btn_open_text

btn_open_text

Sets open button text.

◆ btn_pie

btn_pie

Initializes clear button.

◆ btn_pie_text

btn_pie_text

Sets clear button text.

◆ btn_run

btn_run

Initializes run button.

◆ btn_run_text

btn_run_text

Sets run button text.

◆ btn_save

btn_save

Initializes save button.

◆ btn_save_text

btn_save_text

Sets save button text.

◆ btn_stop

btn_stop

Initializes stop button.

◆ btn_stop_text

btn_stop_text

Sets stop button text.

◆ details_field

details_field

Initializes field for packets details.

◆ dropdown_if_selection

dropdown_if_selection

Current interface selection default is None.

◆ dropdown_interfaces

dropdown_interfaces

Initializes dropdown combo box for interfaces.

◆ feedback_field

feedback_field

Initializes field for feedback text.

◆ filter_input_combobox

filter_input_combobox

Initializes dropdown combo box for filters.

◆ filter_option

filter_option

Initializes filter options to None.

◆ host_name_checkbox

host_name_checkbox

Checkbox that that allows host name mapping.

◆ interfaces

interfaces

Gets interfaces from underlying operating system.

◆ is_filter_wrong

is_filter_wrong

Initializes boolean for a filter option if it is wrong default is False.

◆ is_running

is_running

Status of sniffer default is False.

◆ layout

layout

Creates layout that will be used for a tab.

◆ packets_count

packets_count

Initializes packets captired to None.

◆ progress_label

progress_label

Initializes label for amount of packets captured.

◆ raw_field

raw_field

Initializes field for raw text.

◆ sniffer_results

sniffer_results

Initializes variable for captured results from sniff function.

◆ sniffer_tab

sniffer_tab

Creates tab that will be returned.

◆ sniffer_thread

sniffer_thread

Initializes thread for a sniffer (sniff function runs in its own thread)

◆ source_ips

source_ips

variable that stores source ips for statistics

◆ table

table

Creates table for network capture results.


The documentation for this class was generated from the following file: