當前位置:首頁 » 編程語言 » java硬碟號

java硬碟號

發布時間: 2022-02-24 02:32:58

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

}
}

B. 高分懸賞用java JNI實現獲取硬碟序列號、CPU序列號的實例分 請給出jni調用代碼、相關文件及使用方法!!

你這還不如直接用C去實現,java去調不覺得蛋疼嗎

C. java如何獲取硬碟物理地址

有個笨方法:new File(""); 獲取當前文件的絕對路徑,然後用String類中的split方法截取即可。

D. 用Java怎麼獲取烏班圖伺服器的磁碟序列號

String HDserialnumber=getHdSerialInfo() ;public static String getHdSerialInfo() { String line = ""; String HdSerial = "";//定義變數 硬碟序列號 try { Process proces = Runtime.getRuntime().exec("cmd /c dir c:");//獲取命令行參數 BufferedReader buffreader = new BufferedReader( new InputStreamReader(proces.getInputStream())); while ((line = buffreader.readLine()) != null) { if (line.indexOf("卷的序列號是 ") != -1) { //讀取參數並獲取硬碟序列號 HdSerial = line.substring(line.indexOf("卷的序列號是 ") + "卷的序列號是 ".length(), line.length()); break; // System.out.println(HdSerial); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return HdSerial;//返回硬碟序列號 卷的序列 非物理}

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

試試是否可以:)

F. 我寫的一段java代碼,怎麼存儲到硬碟上的數字信號怎麼轉化成電信號工作原理是什麼

你寫的代碼存放在文件上,自然會寫進硬碟。java代碼被cpu執行,cpu調用操作系統代碼,操作系統發出本地硬體指令,驅動硬體工作。

G. java 如何獲得磁碟名稱

swing下的包,javax.swing.filechooser.FileSystemView;可以獲取:

FileSystemView fileSys=FileSystemView.getFileSystemView(); //獲取當前系統文件類型

//獲取系統的所有盤符或系統卷類型

for(File f:File.listRoots()){

System.out.println(fileSys.getSystemDisplayName(f));//獲取系統卷標及名字

System.out.println(fileSys.getSystemTypeDescription(f));//獲取系統卷的類型

System.out.println(f.getTotalSpace());//獲取該卷大小(單位:位元組)

System.out.println(f.getFreeSpace());//獲取該卷可用大小(單位:位元組)

}

H. java 怎麼獲取硬碟序列號

	
publicstaticvoidmain(String[]args){

StringHDserialnumber=getHdSerialInfo();
System.out.println(HDserialnumber);
}

(){

Stringline="";

StringHdSerial="";//定義變數硬碟序列號
try{
Processproces=Runtime.getRuntime().exec("cmd/cdirc:");//獲取命令行參數
BufferedReaderbuffreader=newBufferedReader(newInputStreamReader(proces.getInputStream()));
while((line=buffreader.readLine())!=null){
if(line.indexOf("卷的序列號是")!=-1){//讀取參數並獲取硬碟序列號
HdSerial=line.substring(line.indexOf("卷的序列號是")+"卷的序列號是".length(),line.length());
break;
}
}
}catch(IOExceptione){
e.printStackTrace();
}
returnHdSerial;//返回硬碟序列號卷的序列非物理

}

I. 怎樣用java 獲取 硬碟 cpu 序列號,可調用dll實現

首先,你要用VC++等寫一個實現此功能的DLL導出函數,然後用JNI調用。

獲取CPU ID的代碼:
CString strTmp;
unsigned long s1,s2;
__asm{
mov eax,01h
xor edx,edx
cpuid
mov s1,edx
mov s2,eax
}
strTmp.Format("%08X%08X",s1,s2);

J. java獲取CPU與硬碟的ID號或調用JNI獲取,急用!!!!

可以用SNMP協議,一般的操作系統都會實現SNMP協議,該協議可以取得你感興趣的計算機的數據,比如CPU,磁碟,內存,等等信息,一般用來做監控計算機信息的一種方式來用,可以去找找SNMP4J的jar及相關文檔

熱點內容
android開發發展 發布:2025-01-09 23:15:36 瀏覽:283
sw裝配體怎麼選擇零件配置 發布:2025-01-09 23:13:17 瀏覽:209
如何進入華為的伺服器 發布:2025-01-09 23:11:37 瀏覽:854
安卓日歷每月提醒怎麼設置 發布:2025-01-09 23:07:53 瀏覽:387
安卓手機qq怎麼備份 發布:2025-01-09 23:07:12 瀏覽:958
kettle源碼下載 發布:2025-01-09 23:01:36 瀏覽:733
casejava 發布:2025-01-09 22:56:56 瀏覽:699
oracle如何導出資料庫 發布:2025-01-09 22:55:13 瀏覽:771
編程ppm 發布:2025-01-09 22:49:25 瀏覽:729
蒸汽之都偵探安卓按鍵在哪裡 發布:2025-01-09 22:48:30 瀏覽:820