def GUIReport(self): #format data for the text box and update gui fields ports = '' #order the ports in the list self.port_list.sort() #read threw though the list for i in self.port_list: self.data = self.data + ';' + str(i) ports = ports + str(i) + ' ' #stuff for stats totaltime = self.end - self.start #get all the info into strings gui_ports = 'Open Ports: ' + ports ports_scanned = '\n' + str(self.count) + ' ports scanned' elapsed_time = '\n' + 'Elapsed Time: ' + str(round(totaltime, 1)) + ' secs' ports_per_sec = '\n' + str(round(self.count / totaltime, 1)) + ' ips/sec' #put it all together, put new line on end so next scan is seperated msg = gui_ports + ports_scanned + elapsed_time + ports_per_sec + '\n' #send to text window with event handler evt = NewTextEvent(TextEventType, -1) evt.setText(msg) wx.PostEvent(self.output_window, evt)
def Scan(self): self.start = time.time() #Send info to text window via our text event evt = NewTextEvent(TextEventType, -1) evt.setText('Scanning host: ' + self.host + ' over ' + str(self.portrange) + ' ports, with a timeout of ' + str(self.timeout)) wx.PostEvent(self.output_window, evt) #send message to status bar evt2 = NewTextEvent(StatusEventType, -1) evt2.setText('Scanning...') wx.PostEvent(self.output_window, evt2) #output for terminal print 'Scanning host: ', self.host, ' over ', self.portrange, ' ports, with a timeout of ', self.timeout #Generate all the consumer threads, pass the queue object, #the host, reference to port_list array, timeout criteria, and #status object instance for i in range(self.threadcount): t = ThreadScan(self.queue, self.host, self.port_list, self.timeout, self.status) t.setDaemon(True) t.start() self.threads.append(t) #fill queue with ports needing to be scanned depending on type #long scan if self.full_scan == True: for a in range(1, self.portrange): self.queue.put(a) self.count = self.count + 1 #short scan elif self.full_scan == False: for a in self.common_ports: self.queue.put(a) self.count = self.count + 1 #wait on the queue until everything has been processed self.queue.join() #send poison pills to kill threads. If the threads aren't killed #then if this class is run multiple times, the threads will exceed #limit for a in range(self.threadcount): self.queue.put(123456789) #wait for threads to die, not working right now , not sure if need #self.queue.join() #recored ending time self.end = time.time() #send message to status bar evt2 = NewTextEvent(StatusEventType, -1) evt2.setText('Scan done') wx.PostEvent(self.output_window, evt2) #reset progress bar evt3 = NewIntEvent(gaugeEventType, -1) evt3.setValue(0) wx.PostEvent(self.output_window, evt3) #build a string with the host name and open ports for writing to disk self.Data() #call the method for handling gui elements self.GUIReport()
def send(self, message): evt1 = NewTextEvent(TextEventType, -1) evt1.setText(message) wx.PostEvent(self.window, evt1)