用InetAddress.getLocalHost可得ip、
用InetAddress.getByName可得机器名
系统名称和版本、用户名、MAC地址用什么方法得到啊???

解决方案 »

  1.   

    System.getProperty("os.name");
    System.getProperty("os.version");
    System.getProperty("user.name");
    可以得到前3项,
    对于MAC地址,用
    调用本地进程“ipconfig/all”
    或取输出 得到以 "Physical Address" 为开头一行,解吸:后面的内容就可以了
      

  2.   

    只是针对win2000等版本,别的不知道行不行。
      

  3.   

    谢谢hvv!
    我用下面的语句可以得到
    System.getProperty("os.name")  -->操作系统名                 
    System.getProperty("os.version")--》版本
    System.getProperty("user.name")--》当前用户
    InetAddress.getLocalHost().getHostAddress()--》ip地址
    InetAddress.getLocalHost().getHostName()--->机器名
    但我想用ipconfig/all里的全部信息
    我用
    try{
    Runtime.getRuntime().exec("C:\\WINNT\\system32\\ipconfig.exe /all");
    }
    catch{
    }
    好象不执行ipconfig.exe /all,不知道有没有其它的办法?
    如何可以执行ipconfig.exe /all,那么如何接受它的信息呢???
      

  4.   

    要获得他的信息,首先要得到他的输入输出流,这样就可以获得全部信息
    import java.io.*; 
    public class Ipcfg
    {
    public static void main(String [] args) throws Exception
    {
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("ipconfig /all");
    BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while((line=br.readLine())!=null)
    {
    System.out.println(line);
    }
    }
    }
      

  5.   

    这样可以得到所有的望卡号,注意有可能不是一个,比如我的机器上旧有3个
    import java.io.*; 
    public class Ipcfg
    {
    public static void main(String [] args) throws Exception
    {
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("ipconfig /all");
    BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while((line=br.readLine())!=null)
    {
    if(line.trim().startsWith("Physical Address")){
    int sp=line.indexOf(":");
    System.out.println("network adapter"+line.substring(sp).trim());
    }

    //System.out.println(line);
    }
    }
    }
      

  6.   

    刚刚有一些小的错误,改正 的如下
    import java.io.*; 
    public class Ipcfg
    {
    public static void main(String [] args) throws Exception
    {
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("ipconfig /all");
    BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while((line=br.readLine())!=null)
    {
    if(line.trim().startsWith("Physical Address")){
    int sp=line.indexOf(":");
    System.out.println("network adapter:"+line.substring(sp+1).trim());
    }

    //System.out.println(line);
    }
    }
    }