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

获取cpu序列号java

发布时间:2022-07-22 00:54:45

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

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

2. 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下如何获得主板序列号呢。

3. 怎么查询cpu序列号

怎么查询cpu序列号?查看方法如下:
1,打开“QQ电脑管家”。
2,点击“工具箱”。
3,点击“硬件检测”。
4,点击“CPU信息”。
5,CPU序列号如下:
拓展资料:
硬盘,CPU都有一个无法修改的识别码。网卡的MAC其实也算一种,但它是可以人为修改的。
软件为了防止盗版,采取了一定的保护措施。在用户注册的时候会根据用户软件所安装的计算机软硬件信息生成唯一的识别码,一般称作机器码,也叫序列号、认证码、注册申请码等。
机器码一般用作软件能够唯一识别的机器,注册软件时会自动根据硬件配置产生一串序号,这串序号叫机器码,软件提供商一般根据用户所提供的机器码来产生唯一的注册码,这样所使用的软件就可以正常工作了。
不过有些黑客们利用机器码和获得的注册码之间的关系,研究出注册码计算器,把机器码输入进去,经过相应的程序计算就能得到注册码。

4. 怎样用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);而调用有参数的方法时,则需要将参数在后面依次传入,注意按顺序噢:

5. 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);

}
}

6. 跪求在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;
}
}
}

试试是否可以:)

7. 如何通过编程读取CPU的序列号

java是可以获取的但是比较麻烦但是还是感觉用C比较方便privatevoidGetInfo(){stringcpuInfo="";//cpu序列号ManagementClasscimobject=newManagementClass("Win32_Processor");ManagementObjectCollectionmoc=cimobject.GetInstances();foreach(ManagementObjectmoinmoc){cpuInfo=mo.Properties["ProcessorId"].Value.ToString();Response.Write("cpu序列号:"+cpuInfo.ToString());}//获取硬盘IDStringHDid;ManagementClasscimobject1=newManagementClass("Win32_DiskDrive");=cimobject1.GetInstances();foreach(ManagementObjectmoinmoc1){HDid=(string)mo.Properties["Model"].Value;Response.Write("硬盘序列号:"+HDid.ToString());}//获取网卡硬件地址=newManagementClass("Win32_NetworkAdapterConfiguration");=mc.GetInstances();foreach(ManagementObjectmoinmoc2){if((bool)mo["IPEnabled"]==true)Response.Write("MACaddress\t{0}"+mo["MacAddress"].ToString());mo.Dispose();}}只有Pentium3能够读取cpu的“序列号”,后来的cpu都没有装配这个信息。一般cpu只能读取cpu的“信息”而不是“序列号”

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

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

阅读全文

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

热点内容
远程海康服务器用什么浏览器 浏览:230
解压报纸图片 浏览:956
python微信公众号开发平台 浏览:895
知识付费网站java源码 浏览:255
方舟怎么做命令管理 浏览:849
linux流量异常 浏览:675
单片机如何给电脑加密码 浏览:519
如何删掉多余的服务器 浏览:220
c编程算法 浏览:833
堵车如何缓解压力 浏览:17
喜鹊快贷app怎么了 浏览:263
海龟编辑器积木编程怎么安装 浏览:185
程序员理发店生意怎么样 浏览:603
程序员罗技 浏览:180
软考初级程序员课程2021下载 浏览:491
杭州程序员奶奶 浏览:880
不听命令造成错误 浏览:981
kool系统源码 浏览:610
流氓app在哪里看 浏览:98
域名购买了怎么指向服务器 浏览:121