在程序中调用ipconfig /all 得到本机的mac
或 nbtstat -a ip(或主机名)得到别的机器的mac

解决方案 »

  1.   

    以前好像讨论过这样的问题
    java不能实现
    用本地方法调用c语言
      

  2.   

    这篇帖子里有我写的例子代码
    http://expert.csdn.net/Expert/topic/2560/2560802.xml?temp=.3973047
      

  3.   

    lapwing2002() :你的帖子打不开啊
      

  4.   

    如果java不能实现,用dll实现然后调用
      

  5.   

    最简单的是通过捕获操作系统里显示网卡信息的命令输出来完成,在WINDOWS里 用ipconfig/all
    否则可以调用C 里实现的DLL
      

  6.   

    import java.io.*;
    public class mac
    {
    public static void main(String[] args)throws Exception
    {
    Runtime r = Runtime.getRuntime();
    Process p =r.exec(args[0]);
    BufferedReader read = new BufferedReader(
    new InputStreamReader(
    p.getInputStream()
    )
    );
    String text;
    while( (text=read.readLine())!=null )
    {
    System.out.println(text);
    }
    }
    }
    在用正则表达式包java.util.regex,筛选一下就可以了。
    java mac ipconfig
      

  7.   

    读取网卡等信息:
    public class NICid {
        public NICid() {
        }    public static void main(String[] args) {
    NICid nicid= new NICid();
    try {
        Process s = Runtime.getRuntime().exec(
    "c:\\windows\\system32\\ipconfig.exe /all");//注意这里是你的windows安装目录,也可以在这里判断windows的安装目录是winnt还是windows或其他
        InputStreamReader ir = new InputStreamReader(s.getInputStream());     LineNumberReader input = new LineNumberReader(ir);     String line;     while ( (line = input.readLine()) != null) { System.out.println("message is ------>" + line);     }
    }
    catch (IOException ex) {
        System.out.print(ex.getMessage());
    }
        }
    }
      

  8.   

    这样也可以
    import java.io.*;
    import java.io.*;
    public class mac
    {
    public static void main(String[] args)throws Exception
    {
    Runtime r = Runtime.getRuntime();
    Process p =r.exec(args[0]);
    BufferedReader read = new BufferedReader(
    new InputStreamReader(
    p.getInputStream()
    )
    );
    String text;
    int index;// 得到":"下标
    int index2;//得到"."下标
    while( (text=read.readLine())!=null )
    {
    System.out.println(text);
    index = text.indexOf(":");
    index2 = text.indexOf(".");
    if( index2 != -1)
    {
    String info = text.substring(0,index2-1);
    System.out.print(info);
    if( index != -1){
             String ip = text.substring(text.indexOf(":")+1);
            System.out.println(ip);
    }
    }
    }
    }
    }