一个可以检查存活ip的窗口程序

#main_window.py ``` #-*- coding: utf-8 -*- from Tkinter import * from success_messagebox import success_msg from target_list import URL_list from Script.live_host import live_ip window = Tk() window.title('TZ扫描器') window.geometry('700x300') l_task = Label(window, text = '任务名称') e_task = Text(window,show=None,width=20,height=1, font = ('Helvetica', '14', 'bold') ) l_task.place(x=100,y=50) e_task.place(x=200,y=50) l_ip = Label(window, text = '目标地址') s_ip = Scrollbar(window) e_ip = Text(window,show=None,width=35,height=5, font = ('Helvetica', '14', 'bold') ) #e_ip.insert(INSERT,'Example: 192.168.1/24;192.168.40.192-195;192.168.1.255') e_ip.insert(INSERT,'192.168.40.194;') l_ip.place(x=100,y=125) e_ip.place(x=200,y=125) def insert_point(): var_task = e_task.get('0.0',END) var_ip = e_ip.get('0.0',END) s = URL_list(var_ip) ip_list = s.filter() print 'All ' + str(len(ip_list)) print ip_list live_list = live_ip(ip_list) print 'alive ' + str(len(live_list)) success_msg() b_run = Button(window,text='开始检测',width=15, height=1,command=insert_point) b_run.place(x=550,y=250) window.mainloop() ``` #live_host.py ``` #-*- coding:utf-8 -*- import os live_list = [] #---------------------------------------------------------------------- def live_ip(ip_list): """""" print len(ip_list) for ip_attr in ip_list: if os.system('ping -n 1 %s' %(ip_attr)) == 0: live_list.append(ip_attr) else: pass return ip_list #live_ip('192.168.40.194') ``` #success_message.py ``` from tkinter import messagebox import tkinter as tk def success_msg(): tk.messagebox.showinfo(title='Info', message='Add Success') #tk.messagebox.showwarning(title='Hi', message='nononono') #tk.messagebox.showerror(title='Success', message='Add Success') #print(tk.messagebox.askquestion(title='Hi', message='hahahaha')) # return 'yes' , 'no' #print(tk.messagebox.askyesno(title='Hi', message='hahahaha')) # return True, False #print(tk.messagebox.asktrycancel(title='Hi', message='hahahaha')) # return True, False #print(tk.messagebox.askokcancel(title='Hi', message='hahahaha')) # return True, False #print(tk.messagebox.askyesnocancel(title="Hi", message="haha")) # return, True, False, None #---------------------------------------------------------------------- def error_msg(): """""" tk.messagebox.showerror(title='Error', message='Something error') #---------------------------------------------------------------------- def Input_error(): """""" tk.messagebox.showwarning(title='Warning', message='Invalid Input') ``` target_list.py ``` #-*- coding: utf-8 -*- from success_messagebox import Input_error ######################################################################## class URL_list: """""" #---------------------------------------------------------------------- def __init__(self, ip_detail): """Constructor""" target_list = [] self.ip_detail = ip_detail self.target_list = target_list #---------------------------------------------------------------------- def filter(self): """""" try: attr = self.ip_detail.split(';') for i in attr: if i.count('.') == 3 and i.find('-') == -1: self.target_list.append(i) elif i.count('.') == 3 and i.find('-') != -1: print '123' ip_seg, ip_end = i.split('-') print ip_seg, ip_end for count in range(int(ip_seg[-1]), int(ip_end) + 1): self.target_list.append(str(ip_seg[0:-2]) + '.' + str(count)) elif i.find('/') != -1: for num_ip in range(1,256): self.target_list.append(str(i[0:-3]) + '.' + str(num_ip)) #print self.target_list return self.target_list except Exception,e: Input_error()

你可能感兴趣的:(一个可以检查存活ip的窗口程序)