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源碼自參考