-
-
Save lasteminista/b0ffcfcdc3f00d4e0bf3c84212803a4f to your computer and use it in GitHub Desktop.
Port Scanner Code Snippet 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import tkinter as tk | |
from tkinter import ttk, font, scrolledtext | |
from ctypes import windll | |
class App(tk.Tk): | |
def __init__(self): | |
... | |
# Default : common ports (shared variable for the radio buttons) | |
self.var = tk.IntVar(value=1) | |
... | |
# Get ports : common, list or range | |
self.option_port_common = ttk.Radiobutton(self, text="Common Ports", variable=self.var, value=1, | |
command=lambda v=self.var: self.select_ports(v)) | |
self.option_port_common.grid(column=0, row=2, sticky=tk.W) | |
self.option_port_list = ttk.Radiobutton(self, text="Ports List", variable=self.var, value=2, | |
command=lambda v=self.var: self.select_ports(v)) | |
self.option_port_list.grid(column=0, row=3, sticky=tk.W) | |
self.option_port_range = ttk.Radiobutton(self, text="Ports Range", variable=self.var, value=3, | |
command=lambda v=self.var: self.select_ports(v)) | |
self.option_port_range.grid(column=0, row=4, sticky=tk.W) | |
... | |
# Get Target Value | |
def get_target(self): ... | |
# Enable Ports Selection | |
def select_ports(self, v): | |
if v.get() == 1: | |
for p in self.port_entries: | |
if p != self.port_common_entry: | |
p.configure(state='disabled') | |
else: | |
p.configure(state='readonly') | |
if v.get() == 2: | |
for p in self.port_entries: | |
if p != self.port_list_entry: | |
p.configure(state='disabled') | |
else: | |
p.configure(state='normal') | |
if v.get() == 3: | |
for p in self.port_entries: | |
if p != self.port_common_entry and p != self.port_list_entry: | |
p.configure(state='normal') | |
else: | |
p.configure(state='disabled') | |
if __name__ == "__main__": | |
app = App() | |
windll.shcore.SetProcessDpiAwareness(1) | |
app.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment