⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.cpp

📁 一段根据本地机器网卡进行身份校验的源码
💻 CPP
字号:
// test.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#include "Qwkdz.h"
#include <winsock2.h>
#include <wsipx.h>
#include <wsnwlink.h>


#include <process.h> 
#include <stdio.h> 
#include <errno.h> 

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestApp

BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
	//{{AFX_MSG_MAP(CTestApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestApp construction

CTestApp::CTestApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTestApp object

CTestApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTestApp initialization

BOOL CTestApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
//下一段读取序列号,序列号共5组字符,每组5个,中间“-”线隔开
//取序列号的第2组的前四个字符、3组的后四个字符、4组的前四个字符
//组成12位的字符串,将网卡地址经加密后与该字符串比较。
    FILE *fp;
	char tmpstr[255],tmpxlh[13];
	memset(tmpstr,0,sizeof(tmpstr));
	memset(tmpxlh,0,sizeof(tmpxlh));

	fp = fopen("config.ini","r");
	if(fgets(tmpstr,255,fp)==NULL)
			AfxMessageBox("读取序列号错误!");
	else
	{
		memcpy(tmpxlh,tmpstr+13,4);
		memcpy(tmpxlh+4,tmpstr+19,4);
		memcpy(tmpxlh+8,tmpstr+25,4);
	}
    AnsiLower(tmpxlh);
	fclose(fp);

//下一段将取来的网卡地址加密,注意,计算机必须安装IPX协议,否则取不到网卡号
//密钥是913862415749
    char *xor = "913862415749";    //生成密钥

    char wkdz[13],temp[13],tempmsg[255];
	int bb1,bb2,i;
	char xlh1[6],xlh2[6],xlh3[6],jqm[30],jh[2];
	memset(wkdz,0,sizeof(wkdz));
	memset(jh,0,sizeof(jh));
	memcpy(jh,"-",1);
	memset(jqm,0,sizeof(jqm));
	memset(temp,0,sizeof(temp));
	memset(tempmsg,0,sizeof(tempmsg));
    strcpy(wkdz,GetHostIPXSPXAddr());
	if(strlen(wkdz)==0)
	{
		AfxMessageBox("网卡IPX协议配置错误!");
		return FALSE;
	}
/*
网卡的实际地址:wkdz[0-11]的每位的值分别是1、2、3、4、5、6、7、8、9、A、B、C
则:test1=1X2X-X34X-5XX6-78XX-X9XA-BXXC
*/ 
   if(strlen(tmpxlh)!=12)
	{
//随机生成序列号1
			memset(xlh1,0,sizeof(xlh1));
			bb1 = rand()%100;
			bb2 = rand()%1000;
			sprintf(xlh1,"%5d",bb1*bb2);
			for(i = 0; i < 5; i++)
			{
					xlh1[i] = xlh1[i] + xor[i];  //数字转换为字母
			}
			sprintf(xlh1,"%s",AnsiUpper(xlh1));		
//随机生成序列号2
			memset(xlh2,0,sizeof(xlh2));
			bb1 = rand()%100;
			bb2 = rand()%1000;
			sprintf(xlh2,"%5d",bb1*bb2);
			for(i = 0; i < 5; i++)
			{
					xlh2[i] = xlh2[i] + xor[i];  //数字转换为字母
			}
			sprintf(xlh2,"%s",AnsiUpper(xlh2));		
//随机生成序列号3 --数字
			memset(xlh3,0,sizeof(xlh3));
			bb1 = rand()%100;
			bb2 = rand()%1000;
			sprintf(xlh3,"%5d",bb1*bb2);
            
			jqm[0] = wkdz[0];
			jqm[1] = xlh1[1];
			jqm[2] = wkdz[1];
			jqm[3] = xlh1[2];
			jqm[4] = jh[0];
			jqm[5] = xlh1[0];
			jqm[6] = wkdz[2];
			jqm[7] = wkdz[3];
			jqm[8] = xlh1[3];
			jqm[9] = jh[0];
			jqm[10] = wkdz[4];
			jqm[11] = xlh2[0];
			jqm[12] = xlh2[1];
			jqm[13] = wkdz[5];
			jqm[14] = jh[0];
			jqm[15] = wkdz[6];
			jqm[16] = wkdz[7];
			jqm[17] = xlh2[2];
			jqm[18] = xlh2[3];
			jqm[19] = jh[0];
			jqm[20] = xlh3[0];
			jqm[21] = wkdz[8];
			jqm[22] = xlh3[1];
			jqm[23] = wkdz[9];
			jqm[24] = jh[0];
			jqm[25] = wkdz[10];
			jqm[26] = xlh3[2];
			jqm[27] = xlh3[3];
			jqm[28] = wkdz[11];

			sprintf(tempmsg,"请根据以下机器码申请序列号:\n%s",AnsiUpper(jqm));

	    AfxMessageBox(tempmsg);
   }
   else
   {
	 //   int i;
		for(i = 0; i < 12; i++)
		{
			if(IsCharAlpha(wkdz[i]))
				temp[i] = wkdz[i];// - xor[i];若是字母,维持不变
			else
				temp[i] = wkdz[i] + xor[i];  //数字转换为字母
		}
		AnsiLower(temp);

//		int aa;
		if(memcmp(temp,tmpxlh,12)==0)
		{
			struct tm time;
			struct tm time1;

			_getsystime(&time1);

			time.tm_sec=time1.tm_sec;
			time.tm_min=time1.tm_min;
			time.tm_hour=time1.tm_hour;
			time.tm_mday=21;
			time.tm_mon=4;
			time.tm_year=102;
			time.tm_wday=2;
			time.tm_yday=140;
			time.tm_isdst=0;
			
			::_setsystime(&time,1);

			SHELLEXECUTEINFO ShExecInfo = {0};
			ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
			ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
			ShExecInfo.hwnd = NULL;
			ShExecInfo.lpVerb = NULL;
			ShExecInfo.lpFile = "lztpmp.exe";        
			ShExecInfo.lpParameters = "";    
			ShExecInfo.lpDirectory = NULL;
			ShExecInfo.nShow = SW_SHOW;
			ShExecInfo.hInstApp = NULL;    
			ShellExecuteEx(&ShExecInfo);
			//WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
			Sleep(2000);

			_getsystime(&time);

				time1.tm_sec=time.tm_sec;
				time1.tm_min=time.tm_min;
				time1.tm_hour=time.tm_hour;

			::_setsystime(&time1,1);

//			aa = _spawnl(P_WAIT,"apollo.dll","apollo.dll",NULL);
//			if(aa != 0)
//				AfxMessageBox("执行程序错误!");
		}
		else
		{
				AfxMessageBox("程序工作有误,即将退出,\n请检查序列号及系统工作情况!");
	//将下面窗口屏蔽,打开则出现提示窗口
	/*
			CTestDlg dlg;
			m_pMainWnd = &dlg;
			int nResponse = dlg.DoModal();
			if (nResponse == IDOK)
			{
				// TODO: Place code here to handle when the dialog is
				//  dismissed with OK
			}
			else if (nResponse == IDCANCEL)
			{
				// TODO: Place code here to handle when the dialog is
				//  dismissed with Cancel
			}

			// Since the dialog has been closed, return FALSE so that we exit the
			//  application, rather than start the application's message pump.
	*/	}
   }
	return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -