Question

I downloaded & installed the latest version of Nmap.

I want to use Nmap to ping & scan but don`t 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.

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");
}

Thanks a lot. Ya Ali.

Était-ce utile?

La solution

Try to write application parameters into the string where you call application.

    g_process->start (QLatin1String ("C:\\Progra~2\\Nmap\\nmap.exe -sn 192.168.1.1"));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top