java 如何获取cpu,主板,硬盘物理序号(请注意是物理序号)
大家能不能提供一下算法,或者,jndi 调用的控件给小弟,小弟现在急用

解决方案 »

  1.   

    用C++应该不难实现。然后用JNI调用就可以了吧。
      

  2.   

    jni 调用C C++ OR DLL
    JAVA本身是很难的。
    LZ您要有写好的我可以帮你调用 让我写SORRY 我不会写
      

  3.   

    晕,我就是要 dll控制,呵呵.jni调用俺当然知道啦.就是没有控制那位高手可以写一个给我.谢谢你啦,
    发到
      

  4.   

    哪个高手可能提供 dll 控件给我用啊.谢谢啦[email protected]
      

  5.   

    被骗.............??如果知道CPC,主板,硬盘物理序列号的算法给我啊.我就谢谢你了.
      

  6.   

    package com.ee2ee.utils;public class SN
    {
    static
    {
    System.loadLibrary("disksn"); //动态库文件名,不要带后缀.dll
    } /*
    功能:JNI调用,调用DLL中的函数,返回硬盘物理序列号
    参数说明:
    key【IN, OUT】: 传递的密钥,各个客户可以使用不同的密钥,目的是防止动态库被非授权用户调用,以及检测返回的密钥是否有效(防止恶意替换动态库)
    nKeyLen【IN】: 密钥长度(字节数)
    sn【OUT】: 保存返回的硬盘物理序列号
    nSize【IN】: 存放硬盘物理序列号的缓冲区(参数sn)大小
    返回值:硬盘物理序列号长度(字节数),返回负数表示错误,如:传递的密钥不正确
    */
    public native static int getDiskSN(byte[] key, int nKeyLen, byte[] sn, int nSize);

    public static String getDiskSN()
    {
    byte[] key = {0x11, 0x22, (byte)0xee, 0x11, 0x3c, 0x72, 0x57, (byte)0x84}; //传递给JNI函数的密钥
    byte[] sn = new byte[128]; //保存硬盘物理序列号

    int nSnLen = getDiskSN(key, key.length, sn, sn.length);

    if (nSnLen < 0) //非法调用(传递的密钥不正确)
    {
    return null;
    }

    //以下应该对返回的密钥进行检测,看是不是和预期的相同,本例中先将其打印出来,然后做比较
    System.out.print("Return key: ");
    for (int i=0; i<key.length; i++)
    {
    String szHex;
    if (key[i] >= 0)
    {
    szHex = Integer.toString(key[i], 16);
    }
    else
    {
    szHex = Integer.toString(256 + key[i], 16); //需要将负数转换成无符号整数
    }

    if (szHex.length() < 2) szHex = "0" + szHex; //补齐2位

    System.out.print(szHex + " ");
    }
    System.out.println();

    byte[] expKey = {0x22, 0x33, 0x75, 0x24, 0x77, 0x54, 0x61, 0x41}; //期望返回的密钥
    if (!java.util.Arrays.equals(key, expKey))
    {
    System.out.println("Return key not equal to expected!");
    return null;
    } try
    {
    return new String(sn, 0, nSnLen, "ISO8859_1");
    }
    catch(java.io.UnsupportedEncodingException ex)
    {
    return null;
    }
    }

    public static void main(String[] args)
    {
    System.out.println("Copyright (C) ee2ee.com. All rights reserved.");
    System.out.println("Notice: Trial version, the last half is masked by \"*\"!");
    System.out.println("disk SN: " + getDiskSN());
    }
    }
      

  7.   

    弱弱地问下:楼上的disksn.dll文件怎么得来的啊?
      

  8.   

    建议楼主去c++板块找人帮写一个dll
      

  9.   

    我也要,给我个?[email protected]
      

  10.   

    http://jawinproject.sourceforge.net/,这个开源项目可以调用dll,并且使用不算难。不过,这里需要一个取得你所需要信息的DLL文件,网上应该有这样的DLL,可以找找
      

  11.   

    这个在系统(system)参数里没有!现在java未提供
      

  12.   

    看看我这下面的代码吧,也许对你有些帮组!
    import java.io.*;
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    public class LocalPC {

    private final String[] windowsCommand = { "ipconfig", "/all" }; private final String[] linuxCommand = { "/sbin/ifconfig", "-a" };

    private StringBuffer buffer;

    public LocalPC(){
    try {
    getLocalPCMessage();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }


    protected String getLocalIPAddress(){
        String localIPAddress=null;
        try {
    localIPAddress= InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
        }
        return localIPAddress;
    }

    private void getLocalPCMessage() throws IOException{
    buffer=new StringBuffer();
    String os=System.getProperty("os.name");
    String[] command;
    if (os.startsWith("Windows")) {
    command = windowsCommand;
    } else if (os.startsWith("Linux")) {
    command = linuxCommand;
    } else {
    throw new IOException("Unknown operating system: " + os);
    }
    Process process=Runtime.getRuntime().exec(command);
    BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
    String text=null;
    for(;(text=reader.readLine())!=null;){
    buffer.append(text+"\n");
    }
    }
    protected String getMACAddress(){
    String macAddress="";
    int number=buffer.indexOf("Physical Address. . . . . . . . . : ");
    int firstIndex=number+"Physical Address. . . . . . . . . : ".length();
    int macLength=17;
    int lastIndex=firstIndex+macLength+1;
    macAddress=buffer.substring(firstIndex, lastIndex);
    return macAddress;
    }
    protected String getSubnetMask(){
    String subnetMask="";
    int number=buffer.indexOf("Subnet Mask . . . . . . . . . . . : ");
    int firstIndex=number+"Subnet Mask . . . . . . . . . . . : ".length();
    int subMask=15;
    int lastIndex=firstIndex+subMask+1;
    subnetMask=buffer.substring(firstIndex, lastIndex).trim();
    return subnetMask;
    }
    protected String getGateway(){
    String gateway="";
    int number=buffer.indexOf("Default Gateway . . . . . . . . . : ");
    int firstIndex=number+"Default Gateway . . . . . . . . . : ".length();
    int gatew=15;
    int lastIndex=firstIndex+gatew+1; 
    gateway=buffer.substring(firstIndex, lastIndex).trim();
    return gateway;
    }
    }
      

  13.   

    为什么不用 webservice 
    webservice 不就是解决跨平台问题的吗
    不过就是安全性差了点
      

  14.   

    虽然用词不雅,但是还是顶楼上的。java得到这些硬件信息,那就不是五星难度了,是不可完成的任务…………
    问问C是咋实现的,然后jni吧
      

  15.   

    能否从java虚拟机中得到这些信息?应该是可以的.