㈠ 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);而調用有參數的方法時,則需要將參數在後面依次傳入,注意按順序噢: