//获取硬盘ID信息及网卡MAC地址的代码
/*+++
HDID.CPP
Written by Lu Lin
http://lu0.126.com
2000.11.3
---*/
#include <windows.h>
#include <iostream.h>
#include <stdio.h>
#define DFP_GET_VERSION 0x00074080
#define DFP_SEND_DRIVE_COMMAND 0x0007c084
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088
#pragma pack(1)
typedef struct _GETVERSIONOUTPARAMS {
BYTE bVersion; // Binary driver version.
BYTE bRevision; // Binary driver revision.
BYTE bReserved; // Not used.
BYTE bIDEDeviceMap; // Bit map of IDE devices.
DWORD fCapabilities; // Bit mask of driver capabilities.
DWORD dwReserved[4]; // For future use.
} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS;
typedef struct _IDEREGS {
BYTE bFeaturesReg; // Used for specifying SMART "commands".
BYTE bSectorCountReg; // IDE sector count register
BYTE bSectorNumberReg; // IDE sector number register
BYTE bCylLowReg; // IDE low order cylinder value
BYTE bCylHighReg; // IDE high order cylinder value
BYTE bDriveHeadReg; // IDE drive/head register
BYTE bCommandReg; // Actual IDE command.
BYTE bReserved; // reserved for future use. Must be zero.
} IDEREGS, *PIDEREGS, *LPIDEREGS;
typedef struct _SENDCMDINPARAMS {
DWORD cBufferSize; // Buffer size in bytes
IDEREGS irDriveRegs; // Structure with drive register values.
BYTE bDriveNumber; // Physical drive number to send
// command to (0,1,2,3).
BYTE bReserved[3]; // Reserved for future expansion.
DWORD dwReserved[4]; // For future use.
//BYTE bBuffer[1]; // Input buffer.
} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS;
typedef struct _DRIVERSTATUS {
BYTE bDriverError; // Error code from driver,
// or 0 if no error.
BYTE bIDEStatus; // Contents of IDE Error register.
// Only valid when bDriverError
// is SMART_IDE_ERROR.
BYTE bReserved[2]; // Reserved for future expansion.
DWORD dwReserved[2]; // Reserved for future expansion.
} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;
typedef struct _SENDCMDOUTPARAMS {
DWORD cBufferSize; // Size of bBuffer in bytes
DRIVERSTATUS DriverStatus; // Driver status structure.
BYTE bBuffer[512]; // Buffer of arbitrary length
// in which to store the data read from the drive.
} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;
typedef struct _IDSECTOR {
USHORT wGenConfig;
USHORT wNumCyls;
USHORT wReserved;
USHORT wNumHeads;
USHORT wBytesPerTrack;
USHORT wBytesPerSector;
USHORT wSectorsPerTrack;
USHORT wVendorUnique[3];
CHAR sSerialNumber[20];
USHORT wBufferType;
USHORT wBufferSize;
USHORT wECCSize;
CHAR sFirmwareRev[8];
CHAR sModelNumber[40];
USHORT wMoreVendorUnique;
USHORT wDoubleWordIO;
USHORT wCapabilities;
USHORT wReserved1;
USHORT wPIOTiming;
USHORT wDMATiming;
USHORT wBS;
USHORT wNumCurrentCyls;
USHORT wNumCurrentHeads;
USHORT wNumCurrentSectorsPerTrack;
ULONG ulCurrentSectorCapacity;
USHORT wMultSectorStuff;
ULONG ulTotalAddressableSectors;
USHORT wSingleWordDMA;
USHORT wMultiWordDMA;
BYTE bReserved[128];
} IDSECTOR, *PIDSECTOR;
/*+++
Global vars
---*/
GETVERSIONOUTPARAMS vers;
SENDCMDINPARAMS in;
SENDCMDOUTPARAMS out;
HANDLE h;
DWORD i;
BYTE j;
void CopyRight(){
cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl;
cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl;
cerr<<"2000.11.3"<<endl<<endl;
}
VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
{
USHORT i;
CHAR temp;
for (i = 0; i < uscStrSize; i+=2)
{
temp = szString[i];
szString[i] = szString[i+1];
szString[i+1] = temp;
}
}
void DetectIDE(BYTE bIDEDeviceMap){
if (bIDEDeviceMap&1){
if (bIDEDeviceMap&16){
cout<<"ATAPI device is attached to primary controller, drive 0."<<endl;
}else{
cout<<"IDE device is attached to primary controller, drive 0."<<endl;
}
}
if (bIDEDeviceMap&2){
if (bIDEDeviceMap&32){
cout<<"ATAPI device is attached to primary controller, drive 1."<<endl;
}else{
cout<<"IDE device is attached to primary controller, drive 1."<<endl;
}
}
if (bIDEDeviceMap&4){
if (bIDEDeviceMap&64){
cout<<"ATAPI device is attached to secondary controller, drive 0."<<endl;
}else{
cout<<"IDE device is attached to secondary controller, drive 0."<<endl;
}
}
if (bIDEDeviceMap&8){
if (bIDEDeviceMap&128){
cout<<"ATAPI device is attached to secondary controller, drive 1."<<endl;
}else{
cout<<"IDE device is attached to secondary controller, drive 1."<<endl;
}
}
}
void hdid9x(){
ZeroMemory(&vers,sizeof(vers));
//We start in 95/98/Me
h=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0);
if (!h){
cout<<"open smartvsd.vxd failed"<<endl;
exit(0);
}
if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
cout<<"DeviceIoControl failed:DFP_GET_VERSION"<<endl;
CloseHandle(h);
return;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Display IDE drive number detected
DetectIDE(vers.bIDEDeviceMap);
//Identify the IDE drives
for (j=0;j<4;j++){
PIDSECTOR phdinfo;
char s[41];
ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;
}
//Close handle before quit
CloseHandle(h);
CopyRight();
}
void hdidnt(){
char hd[80];
PIDSECTOR phdinfo;
char s[41];
ZeroMemory(&vers,sizeof(vers));
//We start in NT/Win2000
for (j=0;j<4;j++){
sprintf(hd,"\\\\.\\PhysicalDrive%d",j);
h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (!h){
continue;
}
if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
CloseHandle(h);
continue;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Identify the IDE drives
ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;
CloseHandle(h);
}
CopyRight();
}
int GetMacAddress(char *mac)
{
NCB ncb;
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
} ASTAT, * PASTAT;
ASTAT Adapter;
// ADAPTER_STATUS Adapter;
LANA_ENUM lana_enum;
UCHAR uRetCode;
memset( &ncb, 0, sizeof(ncb) );
memset( &lana_enum, 0, sizeof(lana_enum));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *) &lana_enum;
ncb.ncb_length = sizeof(LANA_ENUM);
uRetCode = Netbios( &ncb );
if( uRetCode != NRC_GOODRET )
return uRetCode ;
for( int lana=0; lana<lana_enum.length; lana++ )
{
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_enum.lana[lana];
uRetCode = Netbios( &ncb );
if( uRetCode == NRC_GOODRET )
break ;
}
if( uRetCode != NRC_GOODRET )
return uRetCode;
memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_enum.lana[0];
strcpy( (char* )ncb.ncb_callname, "*" );
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios( &ncb );
if( uRetCode != NRC_GOODRET )
return uRetCode ;
sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
return 0;
}
void main(){
char szAddr[20];
GetMacAddress(szAddr);
cout<<"\nNet adapter MAC Address:"<<szAddr<<endl<<endl;
OSVERSIONINFO VersionInfo;
ZeroMemory(&VersionInfo,sizeof(VersionInfo));
VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);
GetVersionEx(&VersionInfo);
switch (VersionInfo.dwPlatformId){
case VER_PLATFORM_WIN32s:
cout<<"Win32s is not supported by this programm."<<endl;
break;
case VER_PLATFORM_WIN32_WINDOWS:
hdid9x();
break;
case VER_PLATFORM_WIN32_NT:
hdidnt();
break;
}
// TODO: Add your control notification handler code here
}
分享到:
相关推荐
用C++获取硬盘的序列号ID以及网卡的MAC地址的源代码,可以用此方式结合md5加密算法进行软件加密。
在这个场景中,`visual c++获得硬盘U盘序列号等所有信息,主机ID,网卡MAC地址_vc9源代码.rar` 提供了使用Visual C++编程语言来获取这些硬件信息的源代码。 Visual C++是Microsoft公司开发的一款强大的C++集成开发...
C++获取计算机的CPU序列号,硬盘序列号(无需管理权限),网卡MAC地址,在vs2005环境下编译通过,已在win10,win7系统测试通过。
总结,通过Qt结合Linux系统调用和文件读取,我们可以轻松获取到网卡MAC地址、CPU ID以及硬盘ID。这个过程不仅提升了程序的可移植性,还使得在不同硬件环境下运行的应用程序能够更好地适应和识别系统资源。
VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号 VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号是计算机系统中获取系统特征码的方法。系统特征码是指网卡MAC、硬盘序列号、CPU ID、BIOS编号等信息,这些信息可以...
本文将详细讲解如何使用C语言在Linux和Windows操作系统下获取CPU序列号、硬盘序列号以及网卡的相关信息,如网卡名称、IP地址、MAC地址和网络连接状态。 首先,让我们关注CPU序列号的获取。在Windows系统中,可以...
本篇文章将详细探讨如何使用Visual Studio 2008(VS2008)来实现获取系统信息,包括CPUID、硬盘ID和网卡MAC地址的功能。我们将主要关注提供的两个源文件:`GetSystemInfo.cpp` 和 `GetSystemInfo.h`。 首先,CPUID...
这些信息包括CPU信息、硬盘ID以及网卡MAC地址。下面是详细的说明: 1. CPU信息获取: - 使用QueryPerformanceCounter函数:该函数属于Windows API的一部分,用于获取高精度的时间间隔,通常与...
"VC获取机器指纹(CPU ID、硬盘ID、MAC地址、BIOS)"这个项目涉及到使用Visual C++(VC)编程语言来获取计算机的一些独特硬件标识,这些标识可以组合成一个唯一的“指纹”。以下是关于这些硬件标识及其获取方法的...
### vC++_获取cpu信息_硬盘ID_网卡MAC地址 #### 设计目的与基本要求 本项目的核心目标在于运用Visual C++编程环境来实现一个实用的应用程序,该程序能够帮助用户收集并显示计算机的基本硬件信息,主要包括CPU型号...
在IT行业中,获取计算机硬件信息是常见的需求,例如硬盘序列号、MAC地址、DNS服务器地址以及网关地址等。这些信息对于系统管理、设备跟踪、网络配置等方面都至关重要。本篇将详细介绍如何利用C++编程语言获取这些...
本资源提供了一个专为Delphi XE10.2设计的源代码,能够帮助开发者轻松获取计算机的硬件ID,包括CPUID、硬盘序列号和网卡MAC地址等关键信息。 首先,我们来了解一下CPUID。CPUID(CPU Identifier)是处理器提供的一...
工具使用c++编写,界面使用MFC。 可以获取计算机id,每个网卡的mac地址,硬盘版本号 硬盘型号及硬盘序列号。支持普通硬盘与固态硬盘。 支持所有win系统获取。
在IT行业中,开发人员经常需要获取计算机硬件的特定标识,如主板ID、硬盘物理ID以及网卡物理地址(MAC地址),这些信息对于软件授权、设备跟踪或其他特定需求至关重要。PowerBuilder是一款强大的4GL(第四代编程语言...
程序运行后,它应该能够显示或打印出当前计算机的网卡MAC地址、硬盘序列号、主板序列号和处理器ID。 总结起来,这个项目展示了如何利用C++和WMI技术来获取系统硬件的关键信息,这对于系统管理和软件开发来说是非常...
在IT行业中,编程是一项至关重要的技能,特别是在Windows操作系统环境下,开发者常常需要获取系统的一些关键信息,如硬盘序列号和网卡MAC地址。本文将详细探讨如何使用VC++(Visual C++)来实现这一功能,主要关注在...
这个名为“CPUID - MAC -硬盘分区ID获取整合版”的项目似乎是一个工具,它能够帮助用户获取计算机中的关键硬件信息,包括中央处理器(CPU)的ID、媒体访问控制(MAC)地址以及硬盘的分区ID。下面将详细解释这些概念...
Cupid通常指的是一个程序或工具,可能用于获取计算机硬件信息,尤其是硬盘ID和网卡MAC地址。源码的提供意味着该工具是开放源代码的,允许用户查看、学习和根据自己的需求进行修改。 【描述分析】 描述中指出,这是...
"c++获得系统信息.rar"这个压缩包文件包含了一个能够获取CPU、硬盘和网卡序列号的程序,对于初学者来说,这是一个很好的学习资源。下面将详细介绍如何在C++中获取这些关键的系统信息。 首先,获取CPU信息通常涉及到...
标题中的"get_MAChd_CPU_BIOS_ID.rar"显然是一款工具或代码库,用于提取计算机的重要硬件标识,包括网卡MAC地址、硬盘序列号、CPU ID以及BIOS的序列号。这些信息对于识别和管理个人电脑或服务器至关重要。 1. **...