当前位置:首页 » 操作系统 » 硬盘序列号源码

硬盘序列号源码

发布时间: 2023-02-14 20:22:50

linux下怎么用c获取硬盘物理序列号

1、在Linux系统中通过C语言获取硬盘序列号,可以借助于ioctl()函数,该函数原型如下:

intioctl(intfd,unsignedlongrequest,...);
ioctl的第一个参数是文件标识符,用open()函数打开设备时获取。
ioctl第二个参数为用于获得指定文件描述符的标志号,获取硬盘序列号,一般指明为HDIO_GET_IDENTITY。
ioctl的第三个参数为一些辅助参数,要获取硬盘序列号,需要借助于structhd_driveid结构体来保存硬盘信息,该结构体在Linux/hdreg.h中,structhd_driveid的声明如下
structhd_driveid{
unsignedshortconfig;/lotsofobsoletebitflags*/
unsignedshortcyls;/*Obsolete,"physical"cyls*/
unsignedshortreserved2;/*reserved(word2)*/
unsignedshortheads;/*Obsolete,"physical"heads*/
unsignedshorttrack_bytes;/*unformattedbytespertrack*/
unsignedshortsector_bytes;/*unformattedbytespersector*/
unsignedshortsectors;/*Obsolete,"physical"sectorspertrack*/
unsignedshortvendor0;/*vendorunique*/
unsignedshortvendor1;/*vendorunique*/
unsignedshortvendor2;/*Retiredvendorunique*/
unsignedcharserial_no[20];/*0=not_specified*/
unsignedshortbuf_type;/*Retired*/
unsignedshortbuf_size;/*Retired,512byteincrements
*0=not_specified
*/
……
};


2、源代码如下

#include<stdio.h>
//ioctl()的声明头文件
#include<sys/ioctl.h>
//硬盘参数头文件,hd_driveid结构声明头文件
#include<linux/hdreg.h>
//文件控制头文件
#include<sys/fcntl.h>
intmain()
{
//用于保存系统返回的硬盘数据信息
structhd_driveidid;
//这里以第一块硬盘为例,用户可自行修改
//用open函数打开获取文件标识符,类似于windows下的句柄
intfd=open("/dev/sda",O_RDONLY|O_NONBLOCK);
//失败返回
if(fd<0){
perror("/dev/sda");
return1;}
//调用ioctl()
if(!ioctl(fd,HDIO_GET_IDENTITY,&id))
{
printf("SerialNumber=%s ",id.serial_no);
}
return0;
}

编译完成后,执行效果如下:

php如何获取本地机(服务器)的硬盘序列号

PHP没有这些功能的,要知道PHP是跨平台的、重点为WEB服务编写的工具。

不过你可以使用其它语言编写一个控制台的EXE文件来获取,然后PHP调用这个程序获取结果,下面程序可以成功执行:

<?php
$s=`dir`;
echo $s;
?>

把DIR换为你获取序列号的EXE文件名字既可

③ VB获取硬盘物理序列号 源码

Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpszVolumeNameBuffer As String, _
ByVal lVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpszFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long

Public Function GetVolumeSerialNumber(ByVal RootPath As String) As String

Dim lpszVolumeNameBuffer As String

Dim lpszFileSystemNameBuffer As String

Dim lVolumeNameSize As Long

Dim lpVolumeSerialNumber As Long

Dim lpMaximumComponentLength As Long

Dim lpFileSystemFlags As Long

Dim nFileSystemNameSize As Long

Dim lRetVal As Long

lpVolumeSerialNumber = 0

lpMaximumComponentLength = 0

lpFileSystemFlags = 0

lpszVolumeNameBuffer = Space$(255)

lpszFileSystemNameBuffer = Space(255)

lVolumeNameSize = Len(lpszVolumeNameBuffer)

nFileSystemNameSize = Len(lpszFileSystemNameBuffer)

lRetVal = GetVolumeInformation(RootPath, _
lpszVolumeNameBuffer, _
lVolumeNameSize, _
lpVolumeSerialNumber, _
lpMaximumComponentLength, _
lpFileSystemFlags, _
lpszFileSystemNameBuffer, _
nFileSystemNameSize)

GetVolumeSerialNumber = Hex$(lpVolumeSerialNumber)

End Function

Private Sub Command1_Click()
Dim sRetVal As String

sRetVal = GetVolumeSerialNumber("C:\")

MsgBox "VolumeSerialNumber is: " & sRetVal

End Sub

只需在窗体建一个COMMAND1。

④ vb6怎样读取win10下硬盘序列号

vb6读取win10下硬盘序列号方法如下:


1、是指硬盘物理序列号,格式化没有变化。

2、支持vista 及win10系统。

3、支持多块硬盘(有的电脑装有几块硬盘)

4、支持串口及并口硬盘。

5、最好是源码或dll 等,代码如下:

  • Visual Basic code

'-------------------添加类模块clsMainInfo-------------------------

Option Explicit

Private Const VER_PLATFORM_WIN32S = 0

Private Const VER_PLATFORM_WIN32_WINDOWS = 1

Private Const VER_PLATFORM_WIN32_NT = 2

Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088

Private Const FILE_SHARE_READ = &H1

Private Const FILE_SHARE_WRITE = &H2

Private Const GENERIC_READ = &H80000000

Private Const GENERIC_WRITE = &H40000000

Private Const OPEN_EXISTING = 3

Private Const Create_NEW = 1

Private Enum HDINFO

HD_MODEL_NUMBER

HD_SERIAL_NUMBER

HD_FIRMWARE_REVISION

End Enum

Private Type OSVERSIONINFO

dwOSVersionInfoSize As Long

dwMajorVersion As Long

dwMinorVersion As Long

dwBuildNumber As Long

dwPlatformId As Long

szCSDVersion As String * 128

End Type

Private Type IDEREGS

bFeaturesReg As Byte

bSectorCountReg As Byte

bSectorNumberReg As Byte

bCylLowReg As Byte

bCylHighReg As Byte

bDriveHeadReg As Byte

bCommandReg As Byte

bReserved As Byte

End Type

Private Type SENDCMDINPARAMS

cBufferSize As Long

irDriveRegs As IDEREGS

bDriveNumber As Byte

bReserved(1 To 3) As Byte

dwReserved(1 To 4) As Long

End Type

Private Type DRIVERSTATUS

bDriveError As Byte

bIDEStatus As Byte

bReserved(1 To 2) As Byte

dwReserved(1 To 2) As Long

End Type

Private Type SENDCMDOUTPARAMS

cBufferSize As Long

DStatus As DRIVERSTATUS

bBuffer(1 To 512) As Byte

End Type

Private Declare Function GetVersionEx _

Lib "kernel32" Alias "GetVersionExA" _

(lpVersionInformation As OSVERSIONINFO) As Long

Private Declare Function CreateFile _

Lib "kernel32" Alias "CreateFileA" _

(ByVal lpFileName As String, _

ByVal dwDesiredAccess As Long, _

ByVal dwShareMode As Long, _

ByVal lpSecurityAttributes As Long, _

ByVal dwCreationDisposition As Long, _

ByVal dwFlagsAndAttributes As Long, _

ByVal hTemplateFile As Long) As Long

Private Declare Function CloseHandle _

Lib "kernel32" _

(ByVal hObject As Long) As Long

Private Declare Function DeviceIoControl _

Lib "kernel32" _

(ByVal hDevice As Long, _

ByVal dwIoControlCode As Long, _

lpInBuffer As Any, _

ByVal nInBufferSize As Long, _

lpOutBuffer As Any, _

ByVal nOutBufferSize As Long, _

lpBytesReturned As Long, _

ByVal lpOverlapped As Long) As Long

Private Declare Sub ZeroMemory _

Lib "kernel32" Alias "RtlZeroMemory" _

(dest As Any, _

ByVal numBytes As Long)

Private Declare Sub CopyMemory _

Lib "kernel32" Alias "RtlMoveMemory" _

(Destination As Any, _

Source As Any, _

ByVal Length As Long)

Private Declare Function GetLastError _

Lib "kernel32" () As Long

Private mvarCurrentDrive As Byte

Private mvarPlatform As String

Public Function GetModelNumber() As String

GetModelNumber = CmnGetHDData(HD_MODEL_NUMBER)

End Function

Public Function GetSerialNumber() As String

GetSerialNumber = CmnGetHDData(HD_SERIAL_NUMBER)

End Function

Public Function GetFirmwareRevision() As String

GetFirmwareRevision = CmnGetHDData(HD_FIRMWARE_REVISION)

End Function

Public Property Let CurrentDrive(ByVal vData As Byte)

If vData < 0 Or vData > 3 Then

Err.Raise 10000, , "Illegal Drive Number"

End If

mvarCurrentDrive = vData

End Property

Public Property Get CurrentDrive() As Byte

CurrentDrive = mvarCurrentDrive

End Property

Public Property Get Platform() As String

Platform = mvarPlatform

End Property

Private Sub Class_Initialize()

Dim OS As OSVERSIONINFO

OS.dwOSVersionInfoSize = Len(OS)

Call GetVersionEx(OS)

mvarPlatform = "Unk"

Select Case OS.dwPlatformId

Case Is = VER_PLATFORM_WIN32S

mvarPlatform = "32S"

Case Is = VER_PLATFORM_WIN32_WINDOWS

If OS.dwMinorVersion = 0 Then

mvarPlatform = "W95"

Else

mvarPlatform = "W98"

End If

Case Is = VER_PLATFORM_WIN32_NT

mvarPlatform = "WNT"

End Select

End Sub

Private Function CmnGetHDData(hdi As HDINFO) As String

Dim bin As SENDCMDINPARAMS

Dim bout As SENDCMDOUTPARAMS

Dim hdh As Long

Dim br As Long

Dim ix As Long

Dim hddfr As Long

Dim hddln As Long

Dim s As String

Select Case hdi

Case HD_MODEL_NUMBER

hddfr = 55

hddln = 40

Case HD_SERIAL_NUMBER

hddfr = 21

hddln = 20

Case HD_FIRMWARE_REVISION

hddfr = 47

hddln = 8

Case Else

Err.Raise 10001, "Illegal HD Data type"

End Select

Select Case mvarPlatform

Case "WNT"

hdh = CreateFile("\.PhysicalDrive" & mvarCurrentDrive, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)

Case "W95", "W98"

hdh = CreateFile("\.Smartvsd", 0, 0, 0, Create_NEW, 0, 0)

Case Else

Err.Raise 10002, , "Illegal platform (only WNT, W98 or W95)"

End Select

If hdh = 0 Then

Err.Raise 10003, , "Error on CreateFile"

End If

ZeroMemory bin, Len(bin)

ZeroMemory bout, Len(bout)

With bin

.bDriveNumber = mvarCurrentDrive

.cBufferSize = 512

With .irDriveRegs

If (mvarCurrentDrive And 1) Then

.bDriveHeadReg = &HB0

Else

.bDriveHeadReg = &HA0

End If

.bCommandReg = &HEC

.bSectorCountReg = 1

.bSectorNumberReg = 1

End With

End With

DeviceIoControl hdh, DFP_RECEIVE_DRIVE_DATA, bin, Len(bin), bout, Len(bout), br, 0

s = vbNullString

For ix = hddfr To hddfr + hddln - 1 Step 2

If bout.bBuffer(ix + 1) = 0 Then Exit For

s = s & Chr(bout.bBuffer(ix + 1))

If bout.bBuffer(ix) = 0 Then Exit For

s = s & Chr(bout.bBuffer(ix))

Next ix

CloseHandle hdh

CmnGetHDData = Trim(s)

End Function

  • Visual Basic code

Option Explicit

'纯vb的获取硬盘序列号代码 (摘自枕善居)

'窗体放置1个ComBox,命名为cbDrive,1个ListBox,命名为lstMain,一个CommandButton,命名为cmdGo,添加如下代码

Dim h As clsMainInfo

Private Sub cmdGo_Click()

Dim hT As Long

Dim uW() As Byte

Dim dW() As Byte

Dim pW() As Byte

Set h = New clsMainInfo

With h

.CurrentDrive = Val(cbDrive.Text)

lstMain.Clear

lstMain.AddItem "当前驱动器: " & .CurrentDrive

lstMain.AddItem ""

lstMain.AddItem "硬盘型号: " & .GetModelNumber

lstMain.AddItem "序列号: " & .GetSerialNumber

lstMain.AddItem "固件版本: " & .GetFirmwareRevision

End With

Set h = Nothing

End Sub

Private Sub Form_Load()

cbDrive.AddItem 0

cbDrive.AddItem 1

cbDrive.AddItem 2

cbDrive.AddItem 3

cbDrive.ListIndex = 0

End Sub

⑤ win10系统硬盘序列号怎么看

首先打开运行窗口,在运行窗口中输入cmd进入命令提示符。

然后在命令提示符中执行命令diskpart来查看硬盘序列号。

⑥ 求获取SCSI硬盘物理序列号的VB源代码

一、关于SCSI硬盘
SCSI的硬盘很多根本没有物理序列号,很多有序列号也无法得到。

这取决于SCSI卡,打个比方,一个单位对果信息公开,公布其每个单位的个人姓名与身份证号,那外界才能知道这个单位的每个人的这方面的情况,如果这个单位不公开,仅告诉你这个单位能为你做什么,那你就没办法了。

很多SCSI卡接上硬盘后,它的硬盘是以一个整体来面向外界的,比如典型的RAID5,4个甚至更多的硬盘对外界来说,就象是在操作一个硬盘一样,至于数据的保存和处理是经过SCSI这个中间层去接管的,外界根本无法获知SCSI卡里面的详情(表现在win中,就是看起来它就是只有一个硬盘)。

如果实在要知道SCSI卡后面硬盘的详情,那得了解某个SCSI卡的硬件接口的具体代码,而这个代码各SCSI卡是完全不同的,多数也是根本不公开的。

二、关于IDE硬盘。
IDE硬盘的序列号是比较容易得到的,也很容易在网上搜到相关的资料。但必需提示的一点是,IDE硬盘并不是所有的品牌、型号都拥有物理序号。

SATA没有试过,不是很清想,你可以用IDE的代码去试试。

三、在当前,抓硬盘物理序号只有一个用处,那就是得到机器唯一特征。很抱歉地说,现在的机器不会,也不允许让你通过一个硬件来得到机器的物征,因为这会给用户自身的安全带来很大的问题!曾经Intel不是想通过在CPU上加上ID来确定机器身份吗?后来因为绝大多数人的反感和抵制而中途而废。

四、在当前,想得到一个机器的特征,只能通过多个硬件来确定!如硬盘型号、主板型号、内存型号、CPU型号等等。

⑦ 谁有C#根据各种机器码自动生成“序列号”的程序源码

if (label2.Text != "") { //把机器码存入数组中 setIntCode();//初始化127位数组 for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中 { Charcode[i] = Convert.ToChar(label2.Text.Substring(i - 1, 1)); }// for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。 { intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]); } string strAsciiName = null;//用于存储机器码 for (int j = 1; j < intNumber.Length; j++) { //MessageBox.Show((Convert.ToChar(intNumber[j])).ToString()); if (intNumber[j] >= 48 && intNumber[j] <= 57)//判断字符ASCII值是否0-9之间 { strAsciiName += Convert.ToChar(intNumber[j]).ToString(); } else if (intNumber[j] >= 65 && intNumber[j] <= 90)//判断字符ASCII值是否A-Z之间 { strAsciiName += Convert.ToChar(intNumber[j]).ToString(); } else if (intNumber[j] >= 97 && intNumber[j] <= 122)//判断字符ASCII值是否a-z之间 { strAsciiName += Convert.ToChar(intNumber[j]).ToString(); } else//判断字符ASCII值不在以上范围内 { if (intNumber[j] > 122)//判断字符ASCII值是否大于z { strAsciiName += Convert.ToChar(intNumber[j] - 10).ToString(); } else { strAsciiName += Convert.ToChar(intNumber[j] - 9).ToString(); } } label3.Text = strAsciiName;//得到注册码 } } else { MessageBox.Show("请选生成机器码","注册提示"); }

麻烦采纳,谢谢!

热点内容
怎么改服务密码 发布:2025-07-27 19:17:16 浏览:636
python小项目源码 发布:2025-07-27 19:12:19 浏览:368
python画矩形 发布:2025-07-27 19:07:31 浏览:994
小米盒子怎么看配置 发布:2025-07-27 19:00:34 浏览:837
百度打开密码是多少 发布:2025-07-27 18:53:11 浏览:22
华为方舟编译器免费使用 发布:2025-07-27 18:53:08 浏览:191
组态王与数据库连接 发布:2025-07-27 18:52:29 浏览:306
dhcp配置错误怎么修复 发布:2025-07-27 18:41:09 浏览:818
我的世界tis服务器的版本 发布:2025-07-27 18:35:50 浏览:552
达内软件编程 发布:2025-07-27 18:33:09 浏览:912