java.net.Inet4Address 的getHostAddress() 方法

解决方案 »

  1.   

    mac地址可以用JNI,但是你要用Applet?
      

  2.   

    对呀,是b/s结构,要用applet的,如何获得本机ip和mac地址呢?期待中。。
      

  3.   

    Applet用JNI也可以做啊,我做过的。不过要签名
      

  4.   

    etre谢谢,麻烦你把代码贴出来,大家一起瞧瞧
      

  5.   

    applet 中如何实现数字签名,这样是不是可以解决
      

  6.   

    非常想知道,看delphi什么的很好实现,不知道java好弄么,不用applet应该方法很多的吧,用applet对这个限制很多么
      

  7.   

    试试这个import java.io.*;
    import java.net.*;public class GetSelfAddress
    {   public GetSelfAddress()
       {
       }
       private static String getMyMac()
       {
           String s = "";
           try
           {
               String s1 = "ipconfig /all";
               Process process = Runtime.getRuntime().exec(s1);
               BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream()));           String line = bufferedreader.readLine();
               for(;line != null;) {
                   String nextLine = bufferedreader.readLine();
                   if(line.indexOf("Physical Address") > 0){
                       int i = line.indexOf("Physical Address") + 36;
                       s = line.substring(i);
                       break;
                   }
                   line = nextLine;
               }
               bufferedreader.close();
               process.waitFor();
           }
           catch(Exception exception)
           {
               s = "";
           }
           return s.trim();
       }
         public static void main(String[] args)
         throws UnknownHostException {
    InetAddress inet = InetAddress.getLocalHost();
    System.out.println(inet.getHostAddress());
         
       System.out.println(GetSelfAddress.getMyMac());
       }
    }