Py学习  »  Python

Python GUI界面版端口扫描工具

释然IT杂谈 • 4 年前 • 365 次点击  

转载于:行者匠心 

值得分享学习学习

一、结构导图
二、部分代码:
# 图形界面
class PortScan(object):
    def __init__(self):
        # 初始化一个窗口实例
        self.window = tk.Tk()  # 初始化一个窗口实例
        self.window.title('Port Scanner (公众号释然IT杂谈)')  # 窗口标题
        self.window.geometry("500x400")  # 窗口大小
        self.ip = 0 # 设置IP

        tk.Label(self.window,text='配置如下:').place(x=10,y=20,anchor='nw')

        # 定义两个单选框:单IP和IP段
        self.var = tk.StringVar()
        tk.Label(self.window,text='扫描方式:').place(x=10,y=50,anchor='nw')
        self.single_ip = tk.Radiobutton(self.window, text='单IP', variable=self.var, value='S')
        self.multi_ip = tk.Radiobutton(self.window, text='IP段', variable=self.var, value='M')

        # IP标签和输入框
        tk.Label(self.window,text='IP:').place(x=10,y=90,anchor='nw')
        self.ip = tk.Entry(self.window,show='')

        # port标签和输入框
        tk.Label(self.window,text='端口:').place(x=10,y=130,anchor='nw')
        self.port = tk.Entry(self.window,show='')

        # 超时标签和输入框
        tk.Label(self.window,text='超时:').place(x=10,y=170,anchor='nw')
        self.time = tk.Entry(self.window,show='',width=5)
        tk.Label(self.window,text='毫秒').place(x=110,y=170,anchor='nw')

        # 线程滚动条
        self.s = tk.Scale(self.window,label='线程',from_=3,to=21,orient=tk.HORIZONTAL,
                     length=200, showvalue=2, tickinterval=6, resolution=1,command=self.thread)
        # 输出文本框
        self.text1 = tk.Text(self.window,height=20,width=30)

        # 按钮:扫描、退出和清空
        tk.Button(self.window,text='扫描',width=5,command=self.scan).place(x=20,y=310,anchor='nw')
        tk.Button(self.window,text='退出',width=5,command=self.exit).place(x=90,y=310,anchor='nw')
        tk.Button(self.window,text='清空',width=5,command=self.delete).place(x=160,y=310,anchor='nw')

        tk.Label(self.window,text='扫描结果:').place(x=250,y=20,anchor='nw')

    # 组件布置/定位
    def gui_arrand(self):
        self.single_ip.place(x=80,y=50,anchor='nw')
        self.multi_ip.place(x=150,y=50,anchor='nw')
        self.ip.place(x=60,y=90,anchor='nw')
        self.port.place(x=60,y=130,anchor='nw')
        self.time.place(x=60,y=170,anchor='nw')
        self.s.place(x=10,y=210,anchor='nw')
        self.text1.place(x=255,y=50,anchor='nw',width='230')
三、运行结果:
四、工具获取:

完整代码获取及生成的exe文件后台回复 “ GUI ” 获取

​

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/135498