Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to use nmap by QProcess?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to use nmap by QProcess?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MohammadReza
    wrote on last edited by
    #1

    Hi friends.

    I downloaded & installed the latest version of Nmap.
    I want to use Nmap to ping & scan but dont know how to do. I can send parameters to CMD to execute namp & run "nmap -sn 192.168.1.1", but I dont want to use CMD.
    I want to send parameters to nmap directly .
    In the other word, Nmap is my process & "-sn" along with "192.168.1.1." are my arguments.

    Thanks a lot.
    Ya Ali.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You have an example right there in "QProcess's documentation":http://qt-project.org/doc/qt-5/qprocess.html#details

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MohammadReza
        wrote on last edited by
        #3

        Hi dear SGaist.
        I searched & read it & another examples but I cant get my expected results. In the other words, just nmap,exe workes but its arguments dont work.

        Here`s my simple code:

        mainwindow.h

        @
        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H

        #include <QMainWindow>
        #include <QProcess>

        namespace Ui {
        class MainWindow;
        }

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

        private:
        Ui::MainWindow *ui;
        QProcess *g_process;

        public slots:
        void ReadData();
        private slots:
        void on_pushButton_clicked();
        };

        #endif // MAINWINDOW_H
        @

        mainwindow.cpp

        @
        #include "mainwindow.h"
        #include "ui_mainwindow.h"

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }

        void MainWindow::ReadData()
        {
        ui->plainTextEdit->appendPlainText(QString(g_process->readAllStandardOutput()));
        }

        void MainWindow::on_pushButton_clicked()
        {
        g_process = new QProcess();

        QObject::connect (g_process, SIGNAL(readyReadStandardOutput()),
            this, SLOT(ReadData()));
        
        
        g_process->start (QLatin1String ("C:\\Progra~2\\Nmap\\nmap.exe"));
        g_process->waitForStarted();
        
        g_process->write ("nmap -sn 192.168.1.1\n\r");
        

        }
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MohammadReza
          wrote on last edited by
          #4

          Solved!
          I must send parameters when I call the start funcion.

          @
          QStringList args;
          args << "namp" << "-sn" << "192.168.1.1";
          g_process->start (QLatin1String ("C:\Progra~2\Nmap\nmap.exe"), args);
          @

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            On a side note, with Qt you can use slashes for paths on all platforms

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved