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

📄 diskid32.cpp

📁 DiskId32最新版 在NT/2000/XP/2003/VISTA下取PATA/SATA/SCSI)下支持获取硬盘的系列号。 编译需要Windows SDK
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   char serialNumber [1024];   char modelNumber [1024];   char revisionNumber [1024];   char bufferSize [32];   __int64 sectors = 0;   __int64 bytes = 0;      //  copy the hard drive serial number to the buffer   ConvertToString (diskdata, 10, 19, serialNumber);   ConvertToString (diskdata, 27, 46, modelNumber);   ConvertToString (diskdata, 23, 26, revisionNumber);   sprintf (bufferSize, "%u", diskdata [21] * 512);   if (0 == HardDriveSerialNumber [0] &&       //  serial number must be alphanumeric       //  (but there can be leading spaces on IBM drives)       (isalnum (serialNumber [0]) || isalnum (serialNumber [19])))   {      strcpy (HardDriveSerialNumber, serialNumber);      strcpy (HardDriveModelNumber, modelNumber);   }#ifdef PRINTING_TO_CONSOLE_ALLOWED   printf ("\nDrive %d - ", drive);   switch (drive / 2)   {      case 0: printf ("Primary Controller - ");              break;      case 1: printf ("Secondary Controller - ");              break;      case 2: printf ("Tertiary Controller - ");              break;      case 3: printf ("Quaternary Controller - ");              break;   }   switch (drive % 2)   {      case 0: printf (" - Master drive\n\n");              break;      case 1: printf (" - Slave drive\n\n");              break;   }   printf ("Drive Model Number________________: [%s]\n",           modelNumber);   printf ("Drive Serial Number_______________: [%s]\n",           serialNumber);   printf ("Drive Controller Revision Number__: [%s]\n",           revisionNumber);   printf ("Controller Buffer Size on Drive___: %s bytes\n",           bufferSize);   printf ("Drive Type________________________: ");   if (diskdata [0] & 0x0080)      printf ("Removable\n");   else if (diskdata [0] & 0x0040)      printf ("Fixed\n");   else printf ("Unknown\n");           		//  calculate size based on 28 bit or 48 bit addressing		//  48 bit addressing is reflected by bit 10 of word 83	if (diskdata [83] & 0x400) 		sectors = diskdata [103] * 65536I64 * 65536I64 * 65536I64 + 					diskdata [102] * 65536I64 * 65536I64 + 					diskdata [101] * 65536I64 + 					diskdata [100];	else		sectors = diskdata [61] * 65536 + diskdata [60];		//  there are 512 bytes in a sector	bytes = sectors * 512;	printf ("Drive Size________________________: %I64d bytes\n",			bytes);#endif  // PRINTING_TO_CONSOLE_ALLOWED   char string1 [1000];   sprintf (string1, "Drive%dModelNumber", drive);   WriteConstantString (string1, modelNumber);   sprintf (string1, "Drive%dSerialNumber", drive);   WriteConstantString (string1, serialNumber);   sprintf (string1, "Drive%dControllerRevisionNumber", drive);   WriteConstantString (string1, revisionNumber);   sprintf (string1, "Drive%dControllerBufferSize", drive);   WriteConstantString (string1, bufferSize);   sprintf (string1, "Drive%dType", drive);   if (diskdata [0] & 0x0080)      WriteConstantString (string1, "Removable");   else if (diskdata [0] & 0x0040)      WriteConstantString (string1, "Fixed");   else      WriteConstantString (string1, "Unknown");}char *ConvertToString (DWORD diskdata [256],		       int firstIndex,		       int lastIndex,		       char* buf){   int index = 0;   int position = 0;      //  each integer has two characters stored in it backwards   for (index = firstIndex; index <= lastIndex; index++)   {         //  get high byte for 1st character      buf [position++] = (char) (diskdata [index] / 256);         //  get low byte for 2nd character      buf [position++] = (char) (diskdata [index] % 256);   }      //  end the string    buf[position] = '\0';      //  cut off the trailing blanks   for (index = position - 1; index > 0 && isspace(buf [index]); index--)      buf [index] = '\0';   return buf;}long getHardDriveComputerID (){   int done = FALSE;   // char string [1024];   __int64 id = 0;   OSVERSIONINFO version;   strcpy (HardDriveSerialNumber, "");   memset (&version, 0, sizeof (version));   version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);   GetVersionEx (&version);   if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)	{		  //  this works under WinNT4 or Win2K if you have admin rights#ifdef PRINTING_TO_CONSOLE_ALLOWED		printf ("\nTrying to read the drive IDs using physical access with admin rights\n");#endif		done = ReadPhysicalDriveInNTWithAdminRights ();			//  this should work in WinNT or Win2K if previous did not work			//  this is kind of a backdoor via the SCSI mini port driver into			//     the IDE drives#ifdef PRINTING_TO_CONSOLE_ALLOWED		printf ("\nTrying to read the drive IDs using the SCSI back door\n");#endif		// if ( ! done) 			done = ReadIdeDriveAsScsiDriveInNT ();		  //  this works under WinNT4 or Win2K or WinXP if you have any rights#ifdef PRINTING_TO_CONSOLE_ALLOWED		printf ("\nTrying to read the drive IDs using physical access with zero rights\n");#endif		//if ( ! done)			done = ReadPhysicalDriveInNTWithZeroRights ();		  //  this works under WinNT4 or Win2K or WinXP or Windows Server 2003 or Vista if you have any rights#ifdef PRINTING_TO_CONSOLE_ALLOWED		printf ("\nTrying to read the drive IDs using Smart\n");#endif		//if ( ! done)			done = ReadPhysicalDriveInNTUsingSmart ();   }   else   {         //  this works under Win9X and calls a VXD      int attempt = 0;         //  try this up to 10 times to get a hard drive serial number      for (attempt = 0;           attempt < 10 && ! done && 0 == HardDriveSerialNumber [0];           attempt++)         done = ReadDrivePortsInWin9X ();   }   if (HardDriveSerialNumber [0] > 0)   {      char *p = HardDriveSerialNumber;      WriteConstantString ("HardDriveSerialNumber", HardDriveSerialNumber);         //  ignore first 5 characters from western digital hard drives if         //  the first four characters are WD-W      if ( ! strncmp (HardDriveSerialNumber, "WD-W", 4))          p += 5;      for ( ; p && *p; p++)      {         if ('-' == *p)             continue;         id *= 10;         switch (*p)         {            case '0': id += 0; break;            case '1': id += 1; break;            case '2': id += 2; break;            case '3': id += 3; break;            case '4': id += 4; break;            case '5': id += 5; break;            case '6': id += 6; break;            case '7': id += 7; break;            case '8': id += 8; break;            case '9': id += 9; break;            case 'a': case 'A': id += 10; break;            case 'b': case 'B': id += 11; break;            case 'c': case 'C': id += 12; break;            case 'd': case 'D': id += 13; break;            case 'e': case 'E': id += 14; break;            case 'f': case 'F': id += 15; break;            case 'g': case 'G': id += 16; break;            case 'h': case 'H': id += 17; break;            case 'i': case 'I': id += 18; break;            case 'j': case 'J': id += 19; break;            case 'k': case 'K': id += 20; break;            case 'l': case 'L': id += 21; break;            case 'm': case 'M': id += 22; break;            case 'n': case 'N': id += 23; break;            case 'o': case 'O': id += 24; break;            case 'p': case 'P': id += 25; break;            case 'q': case 'Q': id += 26; break;            case 'r': case 'R': id += 27; break;            case 's': case 'S': id += 28; break;            case 't': case 'T': id += 29; break;            case 'u': case 'U': id += 30; break;            case 'v': case 'V': id += 31; break;            case 'w': case 'W': id += 32; break;            case 'x': case 'X': id += 33; break;            case 'y': case 'Y': id += 34; break;            case 'z': case 'Z': id += 35; break;         }                                  }   }   id %= 100000000;   if (strstr (HardDriveModelNumber, "IBM-"))      id += 300000000;   else if (strstr (HardDriveModelNumber, "MAXTOR") ||            strstr (HardDriveModelNumber, "Maxtor"))      id += 400000000;   else if (strstr (HardDriveModelNumber, "WDC "))      id += 500000000;   else      id += 600000000;#ifdef PRINTING_TO_CONSOLE_ALLOWED   printf ("\nHard Drive Serial Number__________: %s\n",            HardDriveSerialNumber);   printf ("\nHard Drive Model Number___________: %s\n",            HardDriveModelNumber);   printf ("\nComputer ID_______________________: %I64d\n", id);#endif   return (long) id;}// GetMACAdapters.cpp : Defines the entry point for the console application.//// Author:	Khalid Shaikh [Shake@ShakeNet.com]// Date:	April 5th, 2002//// This program fetches the MAC address of the localhost by fetching the // information through GetAdapatersInfo.  It does not rely on the NETBIOS// protocol and the ethernet adapter need not be connect to a network.//// Supported in Windows NT/2000/XP// Supported in Windows 95/98/Me//// Supports multiple NIC cards on a PC.#include <Iphlpapi.h>#include <Assert.h>#pragma comment(lib, "iphlpapi.lib")// Prints the MAC address stored in a 6 byte array to stdoutstatic void PrintMACaddress(unsigned char MACData[]){#ifdef PRINTING_TO_CONSOLE_ALLOWED	printf("\nMAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 		MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);#endif   char string [256];   sprintf (string, "%02X-%02X-%02X-%02X-%02X-%02X", MACData[0], MACData[1], 			   MACData[2], MACData[3], MACData[4], MACData[5]);   WriteConstantString ("MACaddress", string);}// Fetches the MAC address and prints itDWORD GetMACaddress(void){  DWORD MACaddress = 0;  IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information                                         // for up to 16 NICs  DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo			AdapterInfo,                 // [out] buffer to receive data			&dwBufLen);                  // [in] size of receive data buffer  assert(dwStatus == ERROR_SUCCESS);  // Verify return value is                                      // valid, no buffer overflow  PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to                                               // current adapter info  do {	if (MACaddress == 0)		MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address [4] * 256 + 					pAdapterInfo->Address [3] * 256 * 256 + 					pAdapterInfo->Address [2] * 256 * 256 * 256;    PrintMACaddress(pAdapterInfo->Address); // Print MAC address    pAdapterInfo = pAdapterInfo->Next;    // Progress through linked list  }  while(pAdapterInfo);                    // Terminate if last adapter    return MACaddress;}static void dump_buffer (const char* title,			const unsigned char* buffer,			int len){   int i = 0;   int j;   printf ("\n-- %s --\n", title);   if (len > 0)   {      printf ("%8.8s ", " ");      for (j = 0; j < 16; ++j)      {	    printf (" %2X", j);      }      printf ("  ");      for (j = 0; j < 16; ++j)      {	    printf ("%1X", j);      }      printf ("\n");   }   while (i < len)   {      printf("%08x ", i);      for (j = 0; j < 16; ++j)      {	 if ((i + j) < len)	    printf (" %02x", (int) buffer[i +j]);	 else	    printf ("   ");      }      printf ("  ");      for (j = 0; j < 16; ++j)      {	 if ((i + j) < len)	    printf ("%c", isprint (buffer[i + j]) ? buffer [i + j] : '.');	 else	    printf (" ");      }      printf ("\n");      i += 16;   }   printf ("-- DONE --\n");}int main (int argc, char * argv []){   printf ("To get all details use \"diskid32 /d\"\n");   if (argc > 1 && strstr (argv [1], "/d"))      PRINT_DEBUG = true;   else      PRINT_DEBUG = false;         long id = getHardDriveComputerID ();   GetMACaddress ();   return 0;}

⌨️ 快捷键说明

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