Ⅰ java怎么获取硬盘序列号 iteye
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);
Ⅱ 怎样用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);而调用有参数的方法时,则需要将参数在后面依次传入,注意按顺序噢:
Ⅲ java获取CPU与硬盘的ID号或调用JNI获取,急用!!!!
可以用SNMP协议,一般的操作系统都会实现SNMP协议,该协议可以取得你感兴趣的计算机的数据,比如CPU,磁盘,内存,等等信息,一般用来做监控计算机信息的一种方式来用,可以去找找SNMP4J的jar及相关文档
Ⅳ java web 项目中怎么获取客户端MAC/硬盘序列号/cpu序列号呢小弟虚心求高手
这个是获取不到的,因为客户端与你服务器一般都是经过复杂的网络连接来的,通常拿到的MAC一般是线路上某台路由器的MAC,没有多大意义。至于硬盘序列号和CPU序列号,这根本无法从一个soket连接中取到。就好像,我无法知道比如在QQ聊天中对面是人还是狗一样。
Ⅳ 跪求在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中如何获得计算机的信息。
System.getProperties()
返回的是Properties
Properties 类表示了一个持久的属性集
以下的代码就可以把Properties的内容读出来
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty (key);
System.out.println(key+Property);
}
} catch (Exception e) {
e.printStackTrace();
}
对于补充的回答:
java不能直接得到楼主需要的信息,但是可以采用JNI,即调用C程序,让C得到这些信息
Ⅶ 请教高手:java如何读取硬盘的序列号
以下是JAVA获取硬盘序列号的一种方法,仅供参考:
StringHDserialnumber=getHdSerialInfo();
(){
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;
//System.out.println(HdSerial);
}
}
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
returnHdSerial;//返回硬盘序列号卷的序列非物理
}
Ⅷ 用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;//返回硬盘序列号 卷的序列 非物理}
Ⅸ java如何获取硬盘物理地址
有个笨方法:new File(""); 获取当前文件的绝对路径,然后用String类中的split方法截取即可。