导航:首页 > 编程语言 > java获取cpu序列号

java获取cpu序列号

发布时间:2022-07-24 16:42:17

java如何获取本机主板序列号

public static String getMotherboardSN() {
String result = "";
try {
File file = File.createTempFile("realhowto", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+ "Set colItems = objWMIService.ExecQuery _ \n"
+ " (\"Select * from Win32_BaseBoard\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.SerialNumber \n"
+ " exit for ' do the first cpu only! \n" + "Next \n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec(
"cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(result);
return result.trim();
}

public static void main(String[] args)
{
getMotherboardSN();
}

这个是我在网上找的,但是只能在windows下获得主板序列号,在linux下就不行。我愁~在linux下如何获得主板序列号呢。

㈡ java 能不能获取CPU的ID号,硬盘的序列号

///==============================获取CPU序列号========
package com.test;
import java.io.IOException;
import java.util.Scanner;

public class CpuUtil {
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
Process process = Runtime.getRuntime().exec(
new String[] { "wmic", "cpu", "get", "ProcessorId" });
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String serial = sc.next();
System.out.println(property + ": " + serial);
System.out.println("time:" + (System.currentTimeMillis() - start));
}
}

//=======================获取硬盘序列号==========================
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class DiskUtil {
public static String getSerialNumber(String drive) {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}
public static void main(String[] args) {
String sn = DiskUtil.getSerialNumber("C");
System.out.println(sn);
}

//=============================获取主板序列号====================
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class MiscUtil {
public static String getMotherboardSN() {
String result = "";
try {
File file = File.createTempFile("realhowto", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+ "Set colItems = objWMIService.ExecQuery _ \n"
+ " (\"Select * from Win32_BaseBoard\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.SerialNumber \n"
+ " exit for ' do the first cpu only! \n" + "Next \n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec(
"cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
return result.trim();
}
public static void main(String[] args) {
String cpuId = MiscUtil.getMotherboardSN();
System.out.println(cpuId);

}
}

㈢ CPU已经安装,怎么查询CPU序列号

一、CPU都有一个唯一的ID号,称CPUID,是在制造CPU的时候,由厂家置入到CPU内部的。

二、查看方法:

1、右点开始,选运行,并输入CMD。

三、作用和意义:

由于CPU外在的所有标记、符号,都是可以人为打磨,而CPUID却是终身不变的,只能用软件读出ID号;因此,利用这个原理,CPU ID工具可以显出CPU的确切信息,包括移动版本、主频、外频、二级缓存等关键信息,从而查出超频的CPU,并且醒目地显示出来。

㈣ 如何获取多核,多cpu系统中指定cpu的序列号

参考:http://blog.sina.com.cn/s/blog_53ad467701000c0q.html

在多cpu、多核中,会随机的获得不同的序列号.这就为我们根据cpu序列号来制作注册机带来了很大的麻烦。
Windows 2000/xp允许设置进程和线程的亲缘性。换句话说,可以控制哪个 CPU 能够运行某些线程。这称为硬亲缘性。Windows提供了设置亲缘性的函数SetProcessAffinityMask 。使用它可控制获取指定cpu的序列号。
本文分为2部分:
1、如何获得cpu的序列号。
2、如何获取指定cpu或指定cpu核的序列号。
1、如何获得cpu的序列号。
使用cpuid指令来获取。
在调用CPUID之前,EAX中存放的是功能代码。在调用CPUID之后,EAX,EBX,ECX,EDX存放的是CPU的各种特征信息。这些信息也就是我们通常所说的CPU序列号。
mov eax, 0 //获取制造商信息
cpuid

mov eax, 1 //获得CPU的序列号
cpuid

以下三个函数,可供参考:
function NewCPUID: string;
const
CPUINFO = 'CPU制造商: %S 序列号: %x';
var
s: array[0..19] of Char;
MyCpuID: Integer;
begin
FillChar(s, 20, 0);
asm
push ebx
push ecx
push edx
mov eax, 0
cpuid
mov dword ptr s[0], ebx
mov dword ptr s[4], edx
mov dword ptr s[8], ecx
mov eax, 1
cpuid
mov MyCpuID, edx
pop edx
pop ecx
pop ebx
end;
Result := Format(CPUINFO, [s, MyCpuID]);
end;
function GetCPUID: TCPUID; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI, EAX [email={@Resukt]{@Resukt[/email]}
MOV EAX, 1
DW $A20F {CPUID Command}
STOSD {CPUID[1]}
MOV EAX, EBX
STOSD {CPUID[2]}
MOV EAX, ECX
STOSD {CPUID[3]}
MOV EAX, EDX
STOSD {CPUID[4]}
POP EDI {Restore registers}
POP EBX
end;
//获取cpu的序列号:
function GetCnCPUID(): string;
const
CPUINFO = '%.8x-%.8x-%.8x-%.8x';
var
iEax: Integer;
iEbx: Integer;
iEcx: Integer;
iEdx: Integer;
begin
asm
push ebx
push ecx
push edx
mov eax, 1
DW $A20F//cpuid
mov iEax, eax
mov iEbx, ebx
mov iEcx, ecx
mov iEdx, edx
pop edx
pop ecx
pop ebx
end;
Result := Format(CPUINFO, [iEax, iEbx, iEcx, iEdx]);
end;
2、如何获取指定cpu或指定cpu核的序列号。
根据Windows可以设置进程和线程的亲缘性的特点,使用SetProcessAffinityMask函数,来控制哪个cpu来运行获取序列号的进程,因此也就获取了指定的cpu的序列号。为了和单cpu兼容,建议总是获取第一个cpu的序列号。
procere SetCPU(h: THandle;CpuNo: Integer);
//CpuNo:决定了获得第几个cpu内核的第几个序列号。
var
ProcessAffinity: Cardinal;
_SystemAffinity: Cardinal;
begin
GetProcessAffinityMask(h, ProcessAffinity, _SystemAffinity) ;
ProcessAffinity := CpuNo; //this sets the process to only run on CPU 0
//for CPU 1 only use 2 and for CPUs 1 & 2 use 3
SetProcessAffinityMask(h, ProcessAffinity)
end;
使用方法:
SetCPU(GetCurrentProcess,1); //第一个cpu的第一个cpu内核
ShowMessage(GetCnCPUID);

㈤ 跪求在JAVA里如何获得CPU的序列号,和硬盘的序列号。

利用Runtime call操作系统的命令,具体的命令取决于不同的操作系统,注意不要调用Runtime.getRuntime().exec(String)接口,要用Runtime.getRuntime().exec(String[])这个接口,不然复杂命令的执行会有问题。例子如下(拿cpu个数,其他类似):
定义命令:
WindowsCmd ="cmd.exe /c echo %NUMBER_OF_PROCESSORS%";//windows的特殊
SolarisCmd = {"/bin/sh", "-c", "/usr/sbin/psrinfo | wc -l"};
AIXCmd = {"/bin/sh", "-c", "/usr/sbin/lsdev -Cc processor | wc -l"};
HPUXCmd = {"/bin/sh", "-c", "echo \"map\" | /usr/sbin/cstm | grep CPU | wc -l "};
LinuxCmd = {"/bin/sh", "-c", "cat /proc/cpuinfo | grep ^process | wc -l"};

然后判断系统:
os = System.getProperty("os.name").toLowerCase();

根据不同的操作系统call不同的命令。
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class GetMACAddress
{
public String getMACAddress(String ipAddress)
{
String str = "",strMAC = "",macAddress = "";
try
{
Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for(int i = 1;i < 100;i++)
{
str = input.readLine();
if(str != null)
{
if(str.indexOf("MAC Address") > 1)
{
strMAC = str.substring(str.indexOf("MAC Address") + 14,str.length());
break;
}
}
}
}
catch(IOException ex)
{
return "Can't Get MAC Address!";
}
//
if(strMAC.length() < 17)
{
return "Error!";
}
macAddress = strMAC.substring(0,2) + ":"
+ strMAC.substring(3,5) + ":"
+ strMAC.substring(6,8) + ":"
+ strMAC.substring(9,11) + ":"
+ strMAC.substring(12,14) + ":"
+ strMAC.substring(15,17);
//
return macAddress;
}

public static void main(String[] args)
{
GetMACAddress getMACAddress = new GetMACAddress();
System.out.println(getMACAddress.getMACAddress("172.18.8.225"));

try
{
java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all");
InputStream istr = proc.getInputStream();
byte[] data = new byte[1024];
istr.read(data);
String netdata = new String(data);
System.out.println("Your Mac Address=" + procAll(netdata));
}
catch(IOException e)
{
System.out.println("error=" + e);
}
}

public static String procAll(String str)
{
return procStringEnd(procFirstMac(procAddress(str)));
}

public static String procAddress(String str)
{
int indexof = str.indexOf("Physical Address");
if(indexof > 0)
{
return str.substring(indexof,str.length());
}
return str;
}

public static String procFirstMac(String str)
{
int indexof = str.indexOf(":");
if(indexof > 0)
{
return str.substring(indexof + 1,str.length()).trim();
}
return str;
}

public static String procStringEnd(String str)
{
int indexof = str.indexOf("\r");
if(indexof > 0)
{
return str.substring(0,indexof).trim();
}
return str;
}
}

import java.util.Vector;

class GetNetMAC
{
//网卡物理地址长度
static private final int _physicalLength = 16;

public static void main(String[] args)
{
//output you computer phycail ip address
System.out.println("The MAC Addressis:\t" + getPhysicalAddress());
}

static public String getPhysicalAddress()
{
GetNetMACShell shell = new GetNetMACShell();
String cmd = "cmd.exe /c ipconfig/all";
Vector result;
result = shell.execute(cmd);
return parseCmd(result.toString());
}

//从字符串中解析出所需要获得的字符串
static private String parseCmd(String s)
{
String find = "Physical Address. . . . . . . . . :";
int findIndex = s.indexOf(find);
if(findIndex == -1)
{
return "not find";
}
else
{
return s.substring(findIndex + find.length() + 1,findIndex + find.length() + 1 + _physicalLength);
}
}
}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.util.Vector;

public class GetNetMACShell
{
private Process process = null;

public Vector execute(String shellCommand)
{
try
{
Start(shellCommand);
Vector vResult = new Vector();
DataInputStream in = new DataInputStream(process.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));

String line;
do
{
line = reader.readLine();
if(line == null)
{
break;
}
else
{
vResult.addElement(line);
}
}
while(true);
reader.close();
return vResult;

}
catch(Exception e)
{
//error
return null;
}
}

public void Start(String shellCommand)
{
try
{
if(process != null)
{
kill();
}
Runtime sys = Runtime.getRuntime();
process = sys.exec(shellCommand);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}

public void kill()
{
if(process != null)
{
process.destroy();
process = null;
}
}
}

试试是否可以:)

㈥ Java如何获取CPU标识符

可尝试通过System.getProperties() 这类API获取:
System.getProperty("os.arch") -- cpu架构 ,如x86
os.name --如Windows XP
os.version -- 操作系统版本号

如果还无法满足,可以根据系统的不同,利用Runtime入口去执行命令来获取,比如:
linux 下 可以执行如:
Runtime.getRuntime().exec("cat /proc/cpuinfo |grep vender_id");
之类的语句进行获取

㈦ java web 项目中怎么获取客户端MAC/硬盘序列号/cpu序列号呢小弟虚心求高手

这个是获取不到的,因为客户端与你服务器一般都是经过复杂的网络连接来的,通常拿到的MAC一般是线路上某台路由器的MAC,没有多大意义。至于硬盘序列号和CPU序列号,这根本无法从一个soket连接中取到。就好像,我无法知道比如在QQ聊天中对面是人还是狗一样。

㈧ 如何获取cpu序列号

一、CPU都有一个唯一的ID号,称CPUID,是在制造CPU的时候,由厂家置入到CPU内部的。

二、查看方法:

1、右点开始,选运行,并输入CMD。

三、作用和意义:

由于CPU外在的所有标记、符号,都是可以人为打磨,而CPUID却是终身不变的,只能用软件读出ID号;因此,利用这个原理,CPU ID工具可以显出CPU的确切信息,包括移动版本、主频、外频、二级缓存等关键信息,从而查出超频的CPU,并且醒目地显示出来。

㈨ linux下java怎么获取CPU和硬盘序列号

JDK 目录 jdk1.6.0_21\demo\management\MemoryMonitor 位置 jar demo源码自参考

㈩ 怎样用java 获取 硬盘 cpu 序列号,可调用dll实现

我是通过一个外部的JAR包来间接来获得DLL文件的句柄 的,它就是jacob了,这是java com brige的简写,呵呵, 这个名称起得非常形象吧,我用的版本是jacob 1.9的,你可以到它的官方网站去下载,下载回来的压缩包中会有两个文件我们需要用到的,一个是jacob.dll,一个是jacob.jar,jacob.dll可以将它复制到系统的system32目录下,而jacob.jar文件,直接将它加入到项目的库中就可以了。这两项准备工作完成后,就可以开始尝试调用了。
新建一个类,引入jacob.jar中的两个类,
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
然后通过dll的ControllerId来读取DLL文件
public class Print {
private ActiveXComponent printController = null;
private Dispatch printObj = null;/*** 默认controllerId的方法*/public Print(){try{printController = new ActiveXComponent(POSControler.Controler);
printObj = (Dispatch)printController.getObject();
}catch(Exception e){
printObj = new Dispatch();
如果方法dll中的方法是空参数时,直接call一下就可以了,如
Dispatch.call(printObj,setDefaultFont);而调用有参数的方法时,则需要将参数在后面依次传入,注意按顺序噢:

阅读全文

与java获取cpu序列号相关的资料

热点内容
进入组策略的命令 浏览:133
python数据结构和内存 浏览:25
python软件功能简介 浏览:784
外国程序员一般多少岁退休 浏览:917
怎么看linux和时间服务器 浏览:680
程序员搞笑花名 浏览:501
dota2怎么设置国服服务器地址 浏览:212
单片机高电平驱动 浏览:115
ios多选文件夹 浏览:909
加强行车调度命令管理 浏览:243
服务器已禁用什么意思 浏览:150
部队命令回复 浏览:755
神奇宝贝服务器地图怎么设置 浏览:382
加密算法输出固定长度 浏览:862
程序员去重庆还是武汉 浏览:121
服务器如何撤销网页登录限制 浏览:980
微信公众平台php开发视频教程 浏览:628
怎么看苹果授权绑定的app 浏览:255
压缩机单级压缩比 浏览:380
linux测试php 浏览:971