From 9c368700545c2d8d1b956656bd9648587686e750 Mon Sep 17 00:00:00 2001 From: haraldaarz Date: Wed, 9 Aug 2023 01:37:06 +0200 Subject: [PATCH] Added extra parameter functions --- README.md | 2 ++ main.py | 35 ++++++++++++----------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5cfd763..2446c1f 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,5 @@ Once you have the application running, you can use it to perform scans. Follow t - **Efficient Keyboard Interaction:** Initiate scans using the Return key for quicker navigation. - **Code Optimization:** Remove unnecessary star (*) imports to ensure a cleaner codebase. - **Fix Freeze Bug:** Fix the bug that causes the application to freeze when a large scan is performed. + - Thread for Nmap scan + diff --git a/main.py b/main.py index 0fe64a2..53df300 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,12 @@ import sys import subprocess import os +import threading +from threading import Thread # import ipaddress # import socket from datetime import datetime +from PyQt6.QtCore import QTimer from PyQt6.QtWidgets import * class Window(QMainWindow): @@ -28,11 +31,14 @@ def __init__(self): self.ip_address_input = QLineEdit() self.ports_input = QLineEdit() self.rate_input = QLineEdit() + self.extra_input = QLineEdit() formLayout = QFormLayout() formLayout.addRow("IP address:", self.ip_address_input) formLayout.addRow("Ports:", self.ports_input) formLayout.addRow("Rate:", self.rate_input) + formLayout.addRow("Extra arguments:", self.extra_input) self.rate_input.setPlaceholderText("Optional") + self.extra_input.setPlaceholderText("Optional") self.dialogLayout.addLayout(formLayout) # Create checkboxes for either a TCP or UDP scan. Only one can be selected at a time, and the default is TCP. Make the boxes right next to each other. @@ -55,9 +61,6 @@ def __init__(self): self.dialogLayout.addLayout(checkbox_layout) - - - buttons = QDialogButtonBox() buttons.setStandardButtons( QDialogButtonBox.StandardButton.Cancel @@ -74,11 +77,10 @@ def __init__(self): # Create a QLabel for the status bar self.status_label = QLabel("Status: Idle") self.statusBar().addWidget(self.status_label) - + self.status_bar = self.statusBar() # Store the status bar instance self._createMenu() - #self._createToolBar() - self._createStatusBar() + def buttonOK_clicked(self): ip_address = self.ip_address_input.text() @@ -86,21 +88,17 @@ def buttonOK_clicked(self): rate = self.rate_input.text() protocol = "TCP" if self.tcp_checkbox.isChecked() else "UDP" vuln_scan = self.vuln_checkbox.isChecked() - + extra = self.extra_input.text() # Validate input (you may want to add further validation logic) if not ip_address or not ports: QMessageBox.warning(self, "Input Error", "Please fill in IP and ports.") return - try: - # Construct the nmap command - now = datetime.now() dt_string = now.strftime("%d-%m-%Y-%H-%M-%S") filename = "scan_output-" + dt_string + ".txt" - nmap_cmd = ["nmap", "-sV", "-p", ports, "--stats-every", "1s", "-oG", filename] if rate: @@ -114,6 +112,9 @@ def buttonOK_clicked(self): else: nmap_cmd.extend(["-sU", ip_address]) + if extra: + nmap_cmd.extend(extra.split()) + result = subprocess.run(nmap_cmd, capture_output=True, text=True) # Open a new tab with the contents of the output file @@ -121,8 +122,6 @@ def buttonOK_clicked(self): output_data = file.read() self.create_output_tab(output_data, ip_address) - #QMessageBox.information(self, "Scan complete", "The scan is complete.") - except subprocess.CalledProcessError as e: QMessageBox.warning(self, "Error", f"An error occurred: {e}") @@ -131,7 +130,6 @@ def buttonOK_clicked(self): QMessageBox.warning(self, "Error", f"An unexpected error occurred: {e}") - def create_output_tab(self, content, ip_address): # Create a new tab and add a text area to display the content results_tab = QWidget() @@ -150,8 +148,6 @@ def buttonCancel_clicked(self): pass - - def closeEvent(self, event): if self.tab_widget.count() > 0: message = QMessageBox() @@ -193,7 +189,6 @@ def _createMenu(self): menu.addAction("&Load config", self.close) menu.addAction("&Save config", self.close) - edit_menu = self.menuBar().addMenu("&Edit") edit_menu.addAction("&Undo") edit_menu.addAction("&Redo") @@ -203,12 +198,6 @@ def _createMenu(self): settings_menu.addAction("&About") - # def _createToolBar(self): - # tools = QToolBar() - # tools.addAction("Exit", self.close) - - # self.addToolBar(tools) - def _createStatusBar(self): status = QStatusBar() status.showMessage("Status progess: Running?")