I wanted to create a table like below
The data from the rows is generated continuously . I want to create my table in such a way that rows are created dynamically . I wrote below code (Very new to tinkter, may be just 6 hours new) but the no data is inserted .
from scapy.all import *
from scapy.layers.http import HTTPRequest,HTTPResponse,HTTP # import HTTP packet
from tkinter import ttk
import tkinter as tk
def generateData():
sniff_packets()
def sniff_packets():
window.mainloop() # <<---The window loop
window.after(300, process_packet)
sniff(filter="port 80", prn=process_packet, iface="utun2", store=False)
def process_packet(packet):
print("Called to process_packet() ")
http_packet = str(packet)
if packet.haslayer(HTTP):
#if "www.xyz.com" in http_packet:
# print(http_packet)
if 'XYZ' in http_packet:
if HTTPRequest in packet:
http_request = packet[HTTPRequest]
insertDataDynamic((arrangePacket(str(http_request)))
if HTTPResponse in packet:
http_response = packet[HTTPResponse]
insertDataDynamic((arrangePacket(str(http_request)))
def insertDataDynamic(api_data):
print("Called to insertDataDynamic() ")
treev.insert("", 'end', text ="L1",
values =("DATA ", api_data, "HTTP"))
def arrangePacket(httpLayer):
ret = "***************************************GET PACKET****************************************************\n"
ret += "\n".join(httpLayer.split(r"\r\n"))
ret += "\n *****************************************************************************************************\n"
return ret
if __name__ == "__main__":
window = tk.Tk()
window.resizable(width = 1, height = 1)
treev = ttk.Treeview(window, selectmode ='browse')
treev.pack(side ='right')
# Constructing vertical scrollbar
# with treeview
verscrlbar = ttk.Scrollbar(window,
orient ="vertical",
command = treev.yview)
# Calling pack method w.r.to verical
# scrollbar
verscrlbar.pack(side ='right', fill ='x')
# Configuring treeview
treev.configure(xscrollcommand = verscrlbar.set)
# Defining number of columns
treev["columns"] = ("1","2","3")
# Defining heading
treev['show'] = 'headings'
# Assigning the width and anchor to the
# respective columns
treev.column("1", width = 500, anchor ='c')
treev.column("2", width = 500, anchor ='se')
treev.column("3", width = 500, anchor ='se')
# Assigning the heading names to the
# respective columns
treev.heading("1", text ="Name")
treev.heading("2", text ="Sex")
treev.heading("3", text ="Age")
generateData()
Also as soon as the mainloop starts ,the prn function of scapy doesn't work .