def mass_update(self, hosts): """Update the internal ListStores to reflect the hosts and services passed in. Hosts that have not changed are left alone.""" hosts = set(hosts) services = set() for h in hosts: services.update([s["service_name"] for s in h.services]) # Disable sorting while elements are added. See the PyGTK FAQ 13.43, # "Are there tips for improving performance when adding many rows to a # Treeview?" sort_column_id = self.host_list.get_sort_column_id() self.host_list.set_default_sort_func(lambda *args: -1) self.host_list.set_sort_column_id(-1, gtk.SORT_ASCENDING) self.host_view.freeze_child_notify() self.host_view.set_model(None) it = self.host_list.get_iter_first() # Remove any of our ListStore hosts that aren't in the list passed in. while it: host = self.host_list.get_value(it, 0) if host in hosts: hosts.remove(host) self.host_list.set(it, 1, get_os_icon(host)) it = self.host_list.iter_next(it) else: if not self.host_list.remove(it): it = None # Add any remaining hosts into our ListStore. for host in hosts: self.add_host(host) # Reenable sorting. if sort_column_id != (None, None): self.host_list.set_sort_column_id(*sort_column_id) self.host_view.set_model(self.host_list) self.host_view.thaw_child_notify() it = self.service_list.get_iter_first() # Remove any of our ListStore services that aren't in the list passed # in. while it: service_name = self.service_list.get_value(it, 0) if service_name in services: services.remove(service_name) it = self.service_list.iter_next(it) else: if not self.service_list.remove(it): it = None # Add any remaining services into our ListStore. for service_name in services: self.add_service(service_name)
def add_host(self, host): self.host_list.append([host, get_os_icon(host), host.get_hostname()])
def update_ui(self): """Update the interface's lists of hosts and ports from a parsed scan.""" self.empty = False self.scan_result.scan_host_view.clear_host_list() self.scan_result.scan_host_view.clear_service_list() self.scan_result.scan_result_notebook.topology.update_radialnet() self.hosts = {} self.services = {} for host in self.inventory.get_hosts(): hostname = host.get_hostname() host_page = self.set_host_details(host) for service in host.services: name = service["service_name"] state = service["port_state"] if state not in ["open", "filtered", "open|filtered"]: continue if name not in self.services.keys(): self.services[name] = {"hosts": []} hs = {"host": host, "page": host_page, "hostname": hostname} hs.update(service) self.services[name]["hosts"].append(hs) self.hosts[hostname] = {'host': host, 'page': host_page} host_details = self.hosts[hostname]['page'].host_details host_info = self.hosts[hostname]['host'] try: host_details.set_os_image(get_os_logo(host)) except: host_details.set_os_image(get_os_logo('')) host_details.set_vulnerability_image(get_vulnerability_logo\ (host_info.get_open_ports())) try: icon = get_os_icon(host) except: icon = get_os_icon('') self.scan_result.scan_host_view.add_host( {hostname: { 'stock': icon, 'action': None }}) if len(self.scan_result.scan_host_view.host_list) > 0: # Select the first host found self.host_view_selection.select_iter( self.scan_result.scan_host_view.host_list.get_iter_root()) self.scan_result.scan_host_view.set_services(self.services.keys())