def __init__(self): super(PortsWorkbench, self).__init__() self.signals = { 'on_btn_ports_all_clicked' : self.on_btn_ports_all_clicked, 'on_btn_ports_open_toggled' : self.on_btn_ports_open_toggled, 'on_btn_ports_closed_toggled' : self.on_btn_ports_closed_toggled, 'on_btn_ports_to_scan_toggled' : self.on_btn_ports_to_scan_toggled, 'on_btn_ports_start_clicked' : self.on_btn_ports_start_clicked, 'on_btn_ports_remove_clicked' : self.on_btn_ports_remove_clicked, 'on_btn_ports_remove_all_clicked' : self.on_btn_ports_remove_all_clicked, 'on_btn_ports_start_all_clicked' : self.on_btn_ports_start_all_clicked, 'on_btn_ports_refresh_clicked' : self.on_btn_ports_refresh_clicked, } self.pool_size = MAX_POOL_SIZE self.quie = [] self.builder.connect_signals(self.signals) self.p_table = self.get_input_object('p_table') self.portsTable = PortsTable(self.p_table) self.port_list = PortList()
class PortsWorkbench(BaseWidget): def __init__(self): super(PortsWorkbench, self).__init__() self.signals = { 'on_btn_ports_all_clicked' : self.on_btn_ports_all_clicked, 'on_btn_ports_open_toggled' : self.on_btn_ports_open_toggled, 'on_btn_ports_closed_toggled' : self.on_btn_ports_closed_toggled, 'on_btn_ports_to_scan_toggled' : self.on_btn_ports_to_scan_toggled, 'on_btn_ports_start_clicked' : self.on_btn_ports_start_clicked, 'on_btn_ports_remove_clicked' : self.on_btn_ports_remove_clicked, 'on_btn_ports_remove_all_clicked' : self.on_btn_ports_remove_all_clicked, 'on_btn_ports_start_all_clicked' : self.on_btn_ports_start_all_clicked, 'on_btn_ports_refresh_clicked' : self.on_btn_ports_refresh_clicked, } self.pool_size = MAX_POOL_SIZE self.quie = [] self.builder.connect_signals(self.signals) self.p_table = self.get_input_object('p_table') self.portsTable = PortsTable(self.p_table) self.port_list = PortList() def fill_port_range(self, host, start, end): for i in range(start, end + 1): self.port_list.add_port(Port(i, False, host)) def fill_single_port(self, host, port): self.port_list.add_port(Port(port, False, host)) def refresh_ports(self): self.portsTable.clear() for port in self.port_list.get_port_list_values(): self.portsTable.add_row(port) def on_btn_ports_refresh_clicked(self, widget): self.refresh_ports() def on_btn_ports_all_clicked(self, widget): self.get_input_object('p_open').set_active(True) self.get_input_object('p_closed').set_active(True) self.get_input_object('p_to_scan').set_active(True) def on_btn_ports_open_toggled(self, widget): self.portsTable.set_view_property(model.PORT_OPENED,self.get_input_object('p_open').get_active()) self.refresh_ports() def on_btn_ports_closed_toggled(self, widget): self.portsTable.set_view_property(model.PORT_CLOSED ,self.get_input_object('p_closed').get_active()) self.refresh_ports() def on_btn_ports_to_scan_toggled(self, widget): self.portsTable.set_view_property(model.PORT_PENDING,self.get_input_object('p_to_scan').get_active()) self.refresh_ports() def on_btn_ports_start_clicked(self, widget): p_table = self.get_input_object('p_table') (model, iter) = p_table.get_selection().get_selected() if iter == None: return port = model.get_value(iter, 0) if port != None: if self.pool_size == 0: self.quie.append(port) else: self.pool_size -= 1 Process(group=None,target=self.func,name=None, args=(port,), kwargs={}).run() def func(self, port): start_time = time.time() status = subprocess.call(["nc", "-zv", port.get_host().get_hostname(), str(port.get_port_number())]) port.set_duration(time.time() - start_time) if status == 0: port.set_status(model.PORT_OPENED) elif status > 0: port.set_status(model.PORT_CLOSED) self.pool_size += 1 self.check_quie() def check_quie(self): if self.pool_size < MAX_POOL_SIZE: Process(group=None,target=self.func,name=None, args=(self.quie.pop(),), kwargs={}).run() self.pool_size += 1 def on_btn_ports_start_all_clicked(self, widget): gtk.threads_enter() for port in self.port_list.get_port_list_values(): self.scan_all(port) gtk.threads_leave() def scan_all(self, port): if self.pool_size == 0: self.quie.append(port) else: self.pool_size -= 1 Process(group=None,target=self.func,name=None, args=(port,), kwargs={}).run() def on_btn_ports_remove_clicked(self, widget): p_table = self.get_input_object('p_table') (model, iter) = p_table.get_selection().get_selected() if iter == None: return iter = model.convert_iter_to_child_iter(iter) port = model.get_model().get_value(iter, 0) self.port_list.remove_port(port.get_port_number()) model.get_model().remove(iter) def on_btn_ports_remove_all_clicked(self, widget): self.portsTable.clear() self.port_list.clear() def get_port_list(self): return self.port_list def clear(self): self.port_list.clear() base = { 'glade_file': 'gui/port_scanner_page_ports_table_gtk.glade', 'widget' : 'mainBox', } input = { 'p_all' : 'btn_ports_all', 'p_open' : 'btn_ports_open', 'p_closed' : 'btn_ports_closed', 'p_to_scan' : 'btn_ports_to_scan', 'p_start' : 'btn_ports_start', 'p_remove' : 'btn_ports_remove', 'p_table' : 'tree_ports_result', 'p_refresh' : 'btn_ports_refresh', }