autoformat

This commit is contained in:
Joost Agterhoek 2024-08-15 21:22:21 +02:00
parent f478c787f1
commit f1a3f7101c

View File

@ -3,7 +3,15 @@
# importing tkinter # importing tkinter
import tkinter as tk import tkinter as tk
from generic import sanitize, type_hosts_listed, type_hosts_organized, ip_lookup, domain_lookup, spf_dmarc from generic import (
sanitize,
type_hosts_listed,
type_hosts_organized,
ip_lookup,
domain_lookup,
spf_dmarc,
)
# function to run on pressing # function to run on pressing
# 'ENTER' key from keyboard. # 'ENTER' key from keyboard.
@ -12,46 +20,47 @@ def key_handler_function(event):
print(type(inputs)) print(type(inputs))
sanitized = sanitize.strip_and_list(inputs) sanitized = sanitize.strip_and_list(inputs)
typed = type_hosts_listed.type_hosts(sanitized) typed = type_hosts_listed.type_hosts(sanitized)
textbox.insert('end', typed) textbox.insert("end", typed)
listed = type_hosts_organized.type_hosts(sanitized) listed = type_hosts_organized.type_hosts(sanitized)
# IPs = listed['IPs'] # IPs = listed['IPs']
# below works for updating a global variable (here)... # below works for updating a global variable (here)...
var.set(listed['IPs']) var.set(listed["IPs"])
ip_listbox.delete(0, 'end') ip_listbox.delete(0, "end")
domain_listbox.delete(0, 'end') domain_listbox.delete(0, "end")
url_listbox.delete(0, 'end') url_listbox.delete(0, "end")
email_listbox.delete(0, 'end') email_listbox.delete(0, "end")
for IP in listed['IPs']: for IP in listed["IPs"]:
hostname = ip_lookup.get_hostname(IP) hostname = ip_lookup.get_hostname(IP)
output = "{} => {}".format(IP, hostname[0]) output = "{} => {}".format(IP, hostname[0])
ip_listbox.insert('end', output) ip_listbox.insert("end", output)
for domain in listed['domains']: for domain in listed["domains"]:
ip = domain_lookup.get_ip_address(domain) ip = domain_lookup.get_ip_address(domain)
output = "{} => {}".format(domain, ip) output = "{} => {}".format(domain, ip)
domain_listbox.insert('end', output) domain_listbox.insert("end", output)
for URL in listed['URLs']: for URL in listed["URLs"]:
url_listbox.insert('end', URL) url_listbox.insert("end", URL)
for email in listed['emails']: for email in listed["emails"]:
dmarc, spf = spf_dmarc.lookup(email) dmarc, spf = spf_dmarc.lookup(email)
output_dmarc = "{} => {}".format(email, dmarc) output_dmarc = "{} => {}".format(email, dmarc)
output_spf = "{} => {}".format(email, spf) output_spf = "{} => {}".format(email, spf)
email_listbox.insert('end', output_dmarc, output_spf) email_listbox.insert("end", output_dmarc, output_spf)
def test_button_function(): def test_button_function():
# testing quoting and comma separating hosts, IPs for now, from global StringVar var # testing quoting and comma separating hosts, IPs for now, from global StringVar var
textbox.delete(1.0, 'end') textbox.delete(1.0, "end")
IPs = ', '.join([f'"{host}"' for host in var.get()]) IPs = ", ".join([f'"{host}"' for host in var.get()])
textbox.insert('end', IPs) textbox.insert("end", IPs)
print("var is : {}".format(var.get())) print("var is : {}".format(var.get()))
# ... and printing an updated global variable here! # ... and printing an updated global variable here!
# main application window # main application window
root = tk.Tk() root = tk.Tk()
root.title("Enter IP addresses, URLs, domains, email addresses") root.title("Enter IP addresses, URLs, domains, email addresses")
root.geometry("900x600") root.geometry("900x600")
root.resizable(0,0) root.resizable(0, 0)
# configure the grid # configure the grid
root.columnconfigure(0, weight=1) root.columnconfigure(0, weight=1)
@ -59,7 +68,7 @@ root.columnconfigure(1, weight=1)
root.columnconfigure(2, weight=1) root.columnconfigure(2, weight=1)
root.columnconfigure(3, weight=1) root.columnconfigure(3, weight=1)
#Listing stuff # Listing stuff
# creating widgets # creating widgets
entry = tk.Entry(root, text="Put in IP addresses, URLs, domains, email addresses") entry = tk.Entry(root, text="Put in IP addresses, URLs, domains, email addresses")
@ -74,27 +83,28 @@ url_label = tk.Label(root, text="URL => IP")
url_listbox = tk.Listbox(root) url_listbox = tk.Listbox(root)
email_label = tk.Label(root, text="email address => DMARC/SPF") email_label = tk.Label(root, text="email address => DMARC/SPF")
email_listbox = tk.Listbox(root) email_listbox = tk.Listbox(root)
var = tk.Variable() var = tk.Variable()
entrylabel.grid(column=1, row=0, columnspan=2, sticky='nsew') entrylabel.grid(column=1, row=0, columnspan=2, sticky="nsew")
entry.grid(column=0, row=1, columnspan=4, sticky='nsew') entry.grid(column=0, row=1, columnspan=4, sticky="nsew")
ip_label.grid(column=0, row=2, columnspan=2, sticky='nsew') ip_label.grid(column=0, row=2, columnspan=2, sticky="nsew")
ip_listbox.grid(column=0, row=3, columnspan=2, sticky='nsew') ip_listbox.grid(column=0, row=3, columnspan=2, sticky="nsew")
domain_label.grid(column=2, row=2, columnspan=2, sticky='nsew') domain_label.grid(column=2, row=2, columnspan=2, sticky="nsew")
domain_listbox.grid(column=2, row=3, columnspan=2, sticky='nsew') domain_listbox.grid(column=2, row=3, columnspan=2, sticky="nsew")
url_label.grid(column=0, row=4, columnspan=2, sticky='nsew') url_label.grid(column=0, row=4, columnspan=2, sticky="nsew")
url_listbox.grid(column=0, row=5, columnspan=2, sticky='nsew') url_listbox.grid(column=0, row=5, columnspan=2, sticky="nsew")
email_label.grid(column=2, row=4, columnspan=2, sticky='nsew') email_label.grid(column=2, row=4, columnspan=2, sticky="nsew")
email_listbox.grid(column=2, row=5, columnspan=2, sticky='nsew') email_listbox.grid(column=2, row=5, columnspan=2, sticky="nsew")
# label.grid(column=1, row=2) # label.grid(column=1, row=2)
# textbox.grid(column=1, row=3) # textbox.grid(column=1, row=3)
#Trying out buttons # Trying out buttons
test_button = tk.Button(root, text="comma-separate and add quotes", command=test_button_function) test_button = tk.Button(
root, text="comma-separate and add quotes", command=test_button_function
)
# Binding ENTER key to function # Binding ENTER key to function
entry.bind("<Return>", key_handler_function) entry.bind("<Return>", key_handler_function)
# run the application # run the application
root.mainloop() root.mainloop()