QT-C++ 注册机软件,生成机器码和注册码,支持授权时间
前言一、效果演示二、关键代码1.获取计算机硬件信息2.应用层调用程序链接前言
1、编译环境:
本程序使用的编译环境是QT5.12.0和VS,如果你安装环境不用,你可以通过阅读里面的程序代码,进行代码有效的提取,然后你再自己创建工程进行编译使用。
2、基本描述:
通过获取计算机的硬件信息,然后通过加密组成,生成每个计算机的唯一机器码,类似的方式,按照内部定义的规则,生成相应的组册码。
一、效果演示
二、关键代码
1.获取计算机硬件信息
获取本地计算机的一些基本信息,这样来构成每个机器码的唯一性。
// 获取计算机的CPU的IDQString HardwareInfo::getCPUId() {QString strCpuId = "";unsigned int dwBuf[4] = {0 };unsigned long long ret = 0;__cpuid((int*)(void*)dwBuf, 1);ret = dwBuf[3];ret = ret << 32;QString str0 = QString::number(dwBuf[3], 16).toUpper();QString str0_1 = str0.rightJustified(8, '0');QString str1 = QString::number(dwBuf[0], 16).toUpper();QString str1_1 = str1.rightJustified(8, '0');strCpuId = str0_1 + str1_1;return strCpuId;}// 获取计算机的MAC地址QString HardwareInfo::getHostMacAddress(){// 获取所有网络接口列表QList<QNetworkInterface> nets = QNetworkInterface::allInterfaces();int nCnt = nets.count();QString strMacAddr = "";for (int i = 0; i < nCnt; i++){// 如果此网络接口被激活并且正在运行并且不是回环地址,则就是我们需要找的Mac地址if (nets[i].flags().testFlag(QNetworkInterface::IsUp) && nets[i].flags().testFlag(QNetworkInterface::IsRunning) && !nets[i].flags().testFlag(QNetworkInterface::IsLoopBack)){strMacAddr = nets[i].hardwareAddress();break;}}return strMacAddr;}// 获取计算机的IP地址QString HardwareInfo::getHostIpAddress(){QString strIpAddress;QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();// 获取第一个本主机的IPv4地址int nListSize = ipAddressesList.size();for (int i = 0; i < nListSize; ++i){if (ipAddressesList.at(i) != QHostAddress::LocalHost &&ipAddressesList.at(i).toIPv4Address()) {strIpAddress = ipAddressesList.at(i).toString();break;}}// 如果没有找到,则以本地IP地址为IPif (strIpAddress.isEmpty())strIpAddress = QHostAddress(QHostAddress::LocalHost).toString();return strIpAddress;}
2.应用层调用
外部应用层进行逻辑功能的操作
#include "RegisterMachine.h"#include "Md5Encode.h"#include "HardwareInfo.h"#include <string.h>#include <QClipboard>#include <QSettings>#include <QMessageBox>#include <QInputDialog>RegisterMachine::RegisterMachine(QWidget *parent): QMainWindow(parent){ui.setupUi(this);initEvent();initUI();}void RegisterMachine::initEvent(){connect(ui.btnMachineCopy, &QPushButton::clicked, this, [&](){QClipboard *clip = QApplication::clipboard();clip->setText(ui.lineEditMachine->text());});connect(ui.btnRegisterCopy, &QPushButton::clicked, this, [&](){QClipboard *clip = QApplication::clipboard();clip->setText(ui.lineEditRegister->text());});connect(ui.btnCreateNumber, &QPushButton::clicked, this, [&](){// 生成注册码QString strMachineNum = ui.lineEditMachine->text();bool bForver = ui.checkBoxForever->checkState();if (strMachineNum.isEmpty())return;QDate endDate = ui.dateEdit->date();QString strDateTime("");if (bForver)strDateTime = QString("3022-01-01");// 一千年以后吧elsestrDateTime = endDate.toString("yyyy-MM-dd");QString strSplit = QString(";");QString strBefore = strMachineNum + strSplit + strDateTime;// 加个密转成注册码QString strAfter = HardwareInfo::crypto(strBefore);ui.lineEditRegister->setText(strAfter);});connect(ui.btnLocalMachineCopy, &QPushButton::clicked, this, [&](){QClipboard *clip = QApplication::clipboard();clip->setText(ui.lineEditLocalMachine->text());});}void RegisterMachine::initUI(){QString strMachineCode = HardwareInfo::createMachineCode();ui.lineEditLocalMachine->setText(strMachineCode);ui.dateEdit->setDateTime(QDateTime::currentDateTime());ui.dateEdit->setCalendarPopup(true); this->setWindowIcon(QIcon(":/Resource/logo.png"));}
程序链接
/download/u013083044/86108002
如果觉得《QT-C++ 注册机软件 生成机器码和注册码 支持授权时间》对你有帮助,请点赞、收藏,并留下你的观点哦!