用python的GUI写一个漏洞扫描器,GUI库为Tkinter
时间: 2023-05-16 11:07:19 浏览: 105
python-port-scanner:一个使用 GUI 开发的快速多线程端口扫描器-开源
好的,我可以回答这个问题。以下是一个简单的漏洞扫描器的 Python 代码,使用 Tkinter GUI 库:
```python
import tkinter as tk
import socket
import threading
class PortScanner:
def __init__(self, target, ports):
self.target = target
self.ports = ports
self.open_ports = []
def scan_port(self, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((self.target, port))
if result == 0:
self.open_ports.append(port)
sock.close()
except:
pass
def scan(self):
threads = []
for port in self.ports:
t = threading.Thread(target=self.scan_port, args=(port,))
threads.append(t)
t.start()
for t in threads:
t.join()
class GUI:
def __init__(self, master):
self.master = master
master.title("漏洞扫描器")
self.target_label = tk.Label(master, text="目标:")
self.target_label.grid(row=0, column=0)
self.target_entry = tk.Entry(master)
self.target_entry.grid(row=0, column=1)
self.ports_label = tk.Label(master, text="端口:")
self.ports_label.grid(row=1, column=0)
self.ports_entry = tk.Entry(master)
self.ports_entry.grid(row=1, column=1)
self.scan_button = tk.Button(master, text="扫描", command=self.scan)
self.scan_button.grid(row=2, column=0, columnspan=2)
self.result_label = tk.Label(master, text="")
self.result_label.grid(row=3, column=0, columnspan=2)
def scan(self):
target = self.target_entry.get()
ports = self.ports_entry.get().split(",")
ports = [int(port) for port in ports]
scanner = PortScanner(target, ports)
scanner.scan()
if len(scanner.open_ports) == 0:
self.result_label.config(text="没有发现开放的端口")
else:
self.result_label.config(text="开放的端口: " + ", ".join(str(port) for port in scanner.open_ports))
root = tk.Tk()
gui = GUI(root)
root.mainloop()
```
这个漏洞扫描器使用了 Python 的 socket 模块来扫描指定目标的指定端口。用户可以在 GUI 中输入目标 IP 地址和要扫描的端口列表,然后点击“扫描”按钮开始扫描。扫描完成后,程序会在 GUI 中显示开放的端口列表。
阅读全文