import java.io.*;
import java.util.*;public class MACHomework
{
 static private final int MACLength=18;
 public static void main(String args[])
 {
  System.out.print ("本机的物理地址是:");
  System.out.println(getMACAddress());
 }
 static public String getMACAddress()
 {
  SysCommand syscmd=new SysCommand();
  //系统命令
  String cmd="cmd.exe /c ipconfig/all";
  Vector result;
  result=syscmd.execute(cmd);
  return getCmdStr(result.toString());
 } 
 static public String  getCmdStr(String outstr)
 {
  String find="Physical Address. . . . . . . . . :";
  int findIndex=outstr.indexOf(find);
  if(findIndex==-1)
  {
   return "未知错误!";
  }
  else
  {
   return outstr.substring(findIndex+find.length()+1,findIndex+find.length()+MACLength);
  }
 }
}//SysCommand类
class SysCommand
{
 Process p;
 public Vector execute(String cmd)
 {
  try
  {
   Start(cmd);
   Vector  vResult=new Vector();
   DataInputStream in=new DataInputStream(p.getInputStream());
   BufferedReader myReader=new BufferedReader(new InputStreamReader(in));
   String line;
   do
   {
    line=myReader.readLine();
    if(line==null)
    {
     break;
    }
    else
    {
     vResult.addElement(line);
    }
   }while(true);
   myReader.close();
   return vResult;
  }
  catch(Exception e)
  {
   return null;
   
  } }
 public void Start(String cmd)
 {
  try
  {
   if(p!=null)
   {
    kill();
   }
   Runtime sys=Runtime.getRuntime();
   p=sys.exec(cmd);
   
  }
  catch(Exception e)
  {
   
  }
 }
 public void kill()
 {
  if(p!=null)
  {
   p.destroy ();
   p=null;
  }
 }
  
}

解决方案 »

  1.   

    楼上的,楼主是要用JSP得到,而不是Application,一般用JSP是得不到的,因为exec是要在Application中才可以的,而IE的安全级别是达不到的,假如可以,那么不是让你可以格式化别人的硬盘了。
      

  2.   

    我记得好像jsp语句中有获得客户端ip和mac的方法,我在书上看过!肯定有!去查一下吧!
      

  3.   

    我可以肯定的说,单用java是不可能的。
      

  4.   

    jFresH_MaN(The answer is ......) 的想法是好的!只不过那只能得到本机的IP(服务器)不过你可以把(ipconfig -all)改成(nbtstat -A 客户IP)  再改String find=“MAC Address =”然后再从返回的结果中找出MAC就OK了
      

  5.   

    按照TCP/IP的协议,只可能取得IP,MAC是无法取得的。
    TCP/IP协议中写得很明白,接收终端收到的数据包中的MAC地址是最后一个路由器的MAC地址,而不是发送终端的MAC地址。而IP之上的TCP和HTTP更不会附带MAC地址的信息了。
    所以只靠服务器是绝对没有可能的,只能在客户端安装程序。书上看到的只可能是这种情况。
      

  6.   

    yingle2000(音乐天堂)你说的是不错!但在一定条件下还是可以实现的嘛,就是上面说的一样,你不会用操作系统的一些命令去做啊??非要用纯JAVA去实现???
      

  7.   

    TCP/IP协议中写得很明白,接收终端收到的数据包中的MAC地址是最后一个路由器的MAC地址,而不是发送终端的MAC地址。
    ----------------------------------------------------
    同意该观点!
    不过实现方法可以参考上面的.
      

  8.   

    确实是需要按照上面所说的办法。所以上面我也说:“所以只靠服务器是绝对没有可能的,只能在客户端安装程序。”就是让客户端自己(用程序)把他的MAC地址发送到服务器。