mirror of
https://github.com/ChronosX88/PyNesca.git
synced 2024-11-22 05:02:18 +00:00
Corrected output of current running threads and made some small changes.
This commit is contained in:
parent
e7c9c22c74
commit
9bfcc9020e
@ -2,13 +2,11 @@ import socket
|
|||||||
|
|
||||||
|
|
||||||
class CoreModel:
|
class CoreModel:
|
||||||
def __init__(self):
|
def __init__(self, timeout):
|
||||||
self.defSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.defSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.defSocket.settimeout(int(timeout))
|
||||||
|
|
||||||
def scanIP(self, host, ports, timeout):
|
def scanIP(self, host, ports):
|
||||||
if timeout == '':
|
|
||||||
timeout = '3'
|
|
||||||
self.defSocket.settimeout(3)
|
|
||||||
openPorts = []
|
openPorts = []
|
||||||
for i in ports[0]:
|
for i in ports[0]:
|
||||||
result = self.defSocket.connect_ex((host, int(i)))
|
result = self.defSocket.connect_ex((host, int(i)))
|
||||||
|
@ -2,13 +2,13 @@ import CoreModel
|
|||||||
import Parser
|
import Parser
|
||||||
import threading
|
import threading
|
||||||
import queue
|
import queue
|
||||||
|
import datetime
|
||||||
from PyQt5.Qt import *
|
from PyQt5.Qt import *
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
|
|
||||||
|
|
||||||
class MainPresenter:
|
class MainPresenter:
|
||||||
def __init__(self, ui):
|
def __init__(self, ui):
|
||||||
self.coreModel = CoreModel.CoreModel()
|
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.threads = []
|
self.threads = []
|
||||||
self.isScanEnabled = False
|
self.isScanEnabled = False
|
||||||
@ -17,7 +17,6 @@ class MainPresenter:
|
|||||||
def startScan(self, ipRanges, portsStr, threadNumber, timeout):
|
def startScan(self, ipRanges, portsStr, threadNumber, timeout):
|
||||||
if timeout == '':
|
if timeout == '':
|
||||||
timeout = '3'
|
timeout = '3'
|
||||||
self.isScanEnabled = True
|
|
||||||
cidrIPRanges = Parser.getCIDRFromRanges(ipRanges)
|
cidrIPRanges = Parser.getCIDRFromRanges(ipRanges)
|
||||||
ports = Parser.getPortsFromString(portsStr)
|
ports = Parser.getPortsFromString(portsStr)
|
||||||
ips = []
|
ips = []
|
||||||
@ -27,29 +26,29 @@ class MainPresenter:
|
|||||||
for ip in ips:
|
for ip in ips:
|
||||||
self.queue.put(ip)
|
self.queue.put(ip)
|
||||||
for i in range(int(threadNumber)):
|
for i in range(int(threadNumber)):
|
||||||
self.threads.append(ScanThread(self.queue, ports, timeout))
|
self.threads.append(ScanThread(self.queue, ports, timeout, self))
|
||||||
self.setCurrentThreadsLabel(len(self.threads))
|
self.setCurrentThreadsLabel(len(self.threads))
|
||||||
for thread in self.threads:
|
for thread in self.threads:
|
||||||
thread.signal.connect(self.setLogText)
|
thread.signal.connect(self.setLogText)
|
||||||
thread.finished.connect(self.onThreadExit)
|
thread.exit_signal.connect(self.on_thread_exit)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
def onThreadExit(self):
|
def on_thread_exit(self, thread):
|
||||||
|
self.threads.pop(self.threads.index(thread[0]))
|
||||||
|
self.setCurrentThreadsLabel(len(self.threads))
|
||||||
if len(self.threads) == 0:
|
if len(self.threads) == 0:
|
||||||
self.setCurrentThreadsLabel(0)
|
self.isScanEnabled = False
|
||||||
self.ui.startButton.setText("Start")
|
self.ui.startButton.setText("Start")
|
||||||
else:
|
|
||||||
self.setCurrentThreadsLabel(len(self.threads) - 1)
|
|
||||||
|
|
||||||
def stopScan(self):
|
def stopScan(self):
|
||||||
self.isScanEnabled = False
|
self.isScanEnabled = False
|
||||||
for thread in self.threads:
|
for thread in self.threads:
|
||||||
thread.exit(0)
|
thread.exit_signal.emit(self.threads.index(thread))
|
||||||
self.threads = []
|
thread.exit()
|
||||||
self.queue = queue.Queue()
|
self.queue = queue.Queue()
|
||||||
|
|
||||||
def setLogText(self, string):
|
def setLogText(self, string):
|
||||||
self.ui.dataText.append(str(string) + '\n')
|
self.ui.dataText.append("[" + str(datetime.datetime.now()) + "] " + str(string))
|
||||||
|
|
||||||
def setCurrentThreadsLabel(self, threadNumber):
|
def setCurrentThreadsLabel(self, threadNumber):
|
||||||
self.ui.currentThreadsLabel.setText(str(threadNumber))
|
self.ui.currentThreadsLabel.setText(str(threadNumber))
|
||||||
@ -58,21 +57,24 @@ class MainPresenter:
|
|||||||
class ScanThread(QThread):
|
class ScanThread(QThread):
|
||||||
|
|
||||||
signal = pyqtSignal(str)
|
signal = pyqtSignal(str)
|
||||||
|
exit_signal = pyqtSignal(list) # This signal for correct pop'ing from thread list
|
||||||
|
|
||||||
def __init__(self, scanQueue, ports, timeout, parent=None):
|
def __init__(self, scanQueue, ports, timeout, presenter, parent=None):
|
||||||
QThread.__init__(self, parent)
|
QThread.__init__(self, parent)
|
||||||
self.scanQueue = scanQueue
|
self.scanQueue = scanQueue
|
||||||
self.coreModel = CoreModel.CoreModel()
|
self.coreModel = CoreModel.CoreModel(timeout)
|
||||||
self.ports = ports
|
self.ports = ports
|
||||||
self._stop_event = threading.Event()
|
self._stop_event = threading.Event()
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
self.presenter = presenter
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
if self.scanQueue.empty():
|
if self.scanQueue.empty():
|
||||||
|
self.exit_signal.emit([self])
|
||||||
self.exit(1)
|
self.exit(1)
|
||||||
hostObject = self.scanQueue.get()
|
hostObject = self.scanQueue.get()
|
||||||
open_ports = self.coreModel.scanIP(str(hostObject), self.ports, self.timeout)
|
open_ports = self.coreModel.scanIP(str(hostObject), self.ports)
|
||||||
signalStr = ''.join(str(x) for x in open_ports)
|
signalStr = ''.join(str(x) for x in open_ports)
|
||||||
if(signalStr == ''):
|
if(signalStr == ''):
|
||||||
self.signal.emit(str(hostObject) + ' has no open ports!')
|
self.signal.emit(str(hostObject) + ' has no open ports!')
|
||||||
|
4
main.py
4
main.py
@ -20,12 +20,12 @@ class MyWin(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
def startButtonClicked(self):
|
def startButtonClicked(self):
|
||||||
if self.isScanActive == False:
|
if self.isScanActive == False:
|
||||||
self.isScanActive = True
|
self.presenter.isScanEnabled = True
|
||||||
self.ui.startButton.setText("Stop")
|
self.ui.startButton.setText("Stop")
|
||||||
self.presenter.startScan(self.ui.ipLine.text(), self.ui.portsLine.text(), self.ui.threadsLine.text(),
|
self.presenter.startScan(self.ui.ipLine.text(), self.ui.portsLine.text(), self.ui.threadsLine.text(),
|
||||||
self.ui.timeoutLine.text())
|
self.ui.timeoutLine.text())
|
||||||
else:
|
else:
|
||||||
self.isScanActive = False
|
self.presenter.isScanEnabled = False
|
||||||
self.ui.startButton.setText("Start")
|
self.ui.startButton.setText("Start")
|
||||||
self.presenter.stopScan()
|
self.presenter.stopScan()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user