直接调用windowsAPI吧,估计可以

解决方案 »

  1.   

    我才打算开始学习java
    来取点经!!
    谢谢!
      

  2.   

    看看这个中不:
    import java.io.*;public class ReadMACAddress{
    public static void main(String[] arg){
    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;
    }
    }
      

  3.   

    楼主可以介绍一下你的CMD.EXE /C IPCONFIG /ALL是在哪里执行的吗?你又是如何获取ipconfig返回的信息的呢?你取到返回的信息,应该是将ipconfig的输出重定向了吧?但既然是重定向为何cmd窗口又会出现呢?
      

  4.   

    ipconfig是dos界面的程序,执行的时候会打开cmd窗口进行输入和输出。如果将输入和输出流截取,改变输出目标,应该可以不显示窗口。
      

  5.   

    private String getPhysicalAddress() {
        String cmd = "cmd.exe /c ipconfig/all";
        String strRs="";
        String result="";
        strRs=executeSysCMD(cmd);
        result = parseCmd(strRs);
        return result;
      }
      private String executeSysCMD(String shellCommand) {
        try {
          Start(shellCommand);
          StringBuffer sb = new StringBuffer();
          DataInputStream in = new DataInputStream(p.getInputStream());
          BufferedReader reader = new BufferedReader(new InputStreamReader(in));
          String line;
          do {
            line = reader.readLine();
            if (line == null) {
              break;
            }
            else {
              sb.append(line);
            }
          }
          while (true);
          reader.close();
          return sb.toString();
        }
        catch (Exception e) {
          //error
          return null;
        }
      }
      

  6.   

    你这应该是BS结构的程序啊
    java在server端执行
    应该获得的是server的MAC才对啊
    怎么会是Client的呢
      

  7.   

    public static String procStringEnd(String str){
    int indexof = str.indexOf("\r");
    if(indexof>0)
    return str.substring(0,indexof).trim();
    return str;
    }
    不太明白,为什么需要两句return?
      

  8.   

    zyg158((DD)One-Time Password System)
    不好意思,没看清楚:)
      

  9.   

    to jxncligang:
    没看到第一个return上面的if吗?
      

  10.   

    还是没有搞定.回答一下 zyg158((DD)One-Time Password System)的问题.
    这个实际上是用ORACLE FORM BUILDER开发的WEB程序,为了取得
    MAC,所以追加了数字签名等处理.但是,现在不管是B/S的还是WEB程序,都是出现以上情况的.
    包括在JBUILDER中都是出现的.
      

  11.   

    直接IPCONFIG /ALL
    何须cmd执行