用python的GUI帮我写一个端口扫描器
时间: 2023-05-14 20:07:15 浏览: 91
一款用Python写的端口扫描工具
当然可以,您可以使用Python的Tkinter模块来创建GUI界面,使用socket模块来进行端口扫描。以下是一个简单的示例代码:
```python
import tkinter as tk
import socket
def scan_ports():
target = host_entry.get()
start_port = int(start_port_entry.get())
end_port = int(end_port_entry.get())
for port in range(start_port, end_port+1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
result = s.connect_ex((target, port))
if result == 0:
result_label.config(text=f"Port {port} is open")
s.close()
root = tk.Tk()
root.title("Port Scanner")
host_label = tk.Label(root, text="Target Host:")
host_label.pack()
host_entry = tk.Entry(root)
host_entry.pack()
start_port_label = tk.Label(root, text="Start Port:")
start_port_label.pack()
start_port_entry = tk.Entry(root)
start_port_entry.pack()
end_port_label = tk.Label(root, text="End Port:")
end_port_label.pack()
end_port_entry = tk.Entry(root)
end_port_entry.pack()
scan_button = tk.Button(root, text="Scan Ports", command=scan_ports)
scan_button.pack()
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()
```
您可以在GUI界面中输入目标主机、起始端口和结束端口,然后点击“Scan Ports”按钮进行扫描。扫描结果将会显示在界面上。请注意,这只是一个简单的示例代码,实际上需要更多的错误处理和优化。
阅读全文