当前位置:首页 » 编程语言 » 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及相关文档

热点内容
缓存火影图片 发布:2025-01-09 10:05:00 浏览:645
设置消费密码验证的渠道是什么 发布:2025-01-09 09:59:21 浏览:869
小米9域名服务器地址 发布:2025-01-09 09:59:14 浏览:607
各类数据库 发布:2025-01-09 09:58:30 浏览:252
php判断进制 发布:2025-01-09 09:54:44 浏览:282
何谓编程结构 发布:2025-01-09 09:54:09 浏览:381
python期末 发布:2025-01-09 09:54:01 浏览:709
方舟和辐射4哪个要求配置高 发布:2025-01-09 09:48:14 浏览:876
如何游玩我的世界外国服务器 发布:2025-01-09 09:21:27 浏览:468
乌克兰编程 发布:2025-01-09 09:16:33 浏览:312