[Solved] How to use nmap by QProcess?

  • 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", 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 "" are my arguments.

    Thanks a lot.
    Ya Ali.

  • Lifetime Qt Champion


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

  • 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:


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QProcess>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    Ui::MainWindow *ui;
    QProcess *g_process;

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

    #endif // MAINWINDOW_H


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

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    delete ui;

    void MainWindow::ReadData()

    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->write ("nmap -sn\n\r");


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

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

  • Lifetime Qt Champion

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.