C语言读取电脑识别码

本文介绍了如何使用C语言来读取电脑的唯一识别码,包括CPU序列号、MAC地址、硬盘序列号和主板序列号,以实现软件的“一机一码”授权机制。作者分享了实现过程、流程图和C程序代码,适合对C语言编程和软件授权感兴趣的读者参考。
摘要由CSDN通过智能技术生成

多努力就会有多特殊(neverforever)——仌

关于利用python读取电脑识别码的文章请关注我另一篇文章:
https://blog.csdn.net/weixin_44204327/article/details/85162826

目标

用C语言,读取电脑机器码,通过授权码,只允许软件运行在唯一电脑上,实现“一机一码”。
程序识别的机器码包括

  1. CPU序列号(ID)
  2. 本地连接 无线局域网 以太网的MAC
  3. 硬盘序列号(唯一)
  4. 主板序列号(唯一)

实现方法

软件安装后,运行软件时,通过电脑机器码的唯一性实现授权码的唯一性。

流程图

C代码函数功能简介

在这里插入图片描述

C程序代码

/*******************************  
 函数:
	1.mac:162387C5B7F7(以太、本地、局域)16:23:87:C5:B7:F7#34:23:87:C5:B7:F7#E0:DB:55:B5:9C:16
	2.harddisk硬盘序列号:3W0PKVLE
	3.harddisk和 mac合并为machine_code:3W0PKVLE16:23:87:C5:B7:F7
	4.machine_code去冒号:machine_code:3W0PKVLE162387C5B7F7
	5.获取machine_code奇数位:oddnumber:30KL328CBF
	6.奇数位加密: Key:996837194
	7.注册程序
	8.登录程序
  主函数:main()
********************************/
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <winsock2.h>
#include <Iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "Iphlpapi.lib")
#include <locale.h>
#include <tchar.h>
#include <windows.h>


// 1.1 MAC函数(以太网、本地、局域)
void byte2Hex(unsigned char bData, unsigned char hex[])
{
   
	int high = bData / 16, low = bData % 16;
	hex[0] = (high <10) ? ('0' + high) : ('A' + high - 10);
	hex[1] = (low <10) ? ('0' + low) : ('A' + low - 10);
}
// 1.2 获取本机MAC地址 
int getLocalMac(unsigned char *mac) 
{
   
	ULONG ulSize = 0;
	PIP_ADAPTER_INFO pInfo = NULL;
	int temp = 0;
	temp = GetAdaptersInfo(pInfo, &ulSize);//第一次调用,获取缓冲区大小
	pInfo = (PIP_ADAPTER_INFO)malloc(ulSize);
	temp = GetAdaptersInfo(pInfo, &ulSize);

	int iCount = 0;
	while (pInfo)//遍历每一张网卡
	{
   
		//  pInfo->Address 是MAC地址
		for (int i = 0; i<(int)pInfo->AddressLength; i++)
		{
   
			byte2Hex(pInfo->Address[i], &mac[iCount]);
			iCount += 2;
			if (i<(int)pInfo->AddressLength - 1)
			{
   
				mac[iCount++] = ':';
			}
			else
			{
   
				mac[iCount++] = '#';
			}
		}
		pInfo = pInfo->Next;
	}
	if (iCount >0)
	{
   
		mac[--iCount] = '\0';
		return iCount;
	}
	else return -1;
}

// 2.获取harddisk
// 2.1 harddisk函数
char * flipAndCodeBytes(const char * str, int pos, int flip, char * buf)
{
   
	int i;
	int j = 0;
	int k = 0;<
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值