大虾们:
    请问怎么样取客户的mac呢???在线等!!!!不够了在加分!!!
    try {
   Process process = Runtime.getRuntime().exec("ipconfig /all");
   InputStreamReader ir = new InputStreamReader(process.getInputStream());
    LineNumberReader input = new LineNumberReader(ir);
    String line;
    while ((line = input.readLine()) != null)
    if (line.indexOf("Physical Address") > 0) 
    {
     String MACAddr = line.substring(line.indexOf("-") - 2);
     System.out.println("MAC address = [" + MACAddr + "]");
    }
    } 
    catch (java.io.IOException e) 
     {
     System.out.println("IOException " + e.getMessage());
     }
以上代码取到的是服务器的mac而并非客户的mac,怎么样取得客户的mac呢???急!!!!在线等!!!!一定加分!!!

解决方案 »

  1.   

    <HTML><HEAD><TITLE>WMI   Scripting   HTML</TITLE>   
      <META   http-equiv=Content-Type   content="text/html;   charset=gb2312">   
      <SCRIPT   language=JScript   event="OnCompleted(hResult,pErrorObject,   pAsyncContext)"   for=foo>   
      document.forms[0].txtMACAddr.value=unescape(MACAddr);   
      document.forms[0].txtIPAddr.value=unescape(IPAddr);   
      document.forms[0].txtDNSName.value=unescape(sDNSName);   
      //document.formbar.submit();   
          </SCRIPT>   
        
      <SCRIPT   language=JScript   event=OnObjectReady(objObject,objAsyncContext)   for=foo>   
            if(objObject.IPEnabled   !=   null   &&   objObject.IPEnabled   !=   "undefined"   &&   objObject.IPEnabled   ==   true)   
            {   
              if(objObject.MACAddress   !=   null   &&   objObject.MACAddress   !=   "undefined")   
              MACAddr   =   objObject.MACAddress;   
              if(objObject.IPEnabled   &&   objObject.IPAddress(0)   !=   null   &&   objObject.IPAddress(0)   !=   "undefined")   
              IPAddr   =   objObject.IPAddress(0);   
              if(objObject.DNSHostName   !=   null   &&   objObject.DNSHostName   !=   "undefined")   
              sDNSName   =   objObject.DNSHostName;   
              }   
          </SCRIPT>   
        
      <META   content="MSHTML   6.00.2800.1106"   name=GENERATOR></HEAD>   
      <BODY>   
      <OBJECT   id=locator   classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6   VIEWASTEXT></OBJECT>   
      <OBJECT   id=foo   classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>   
      <SCRIPT   language=JScript>   
            var   service   =   locator.ConnectServer();   
            var   MACAddr   ;   
            var   IPAddr   ;   
            var   DomainAddr;   
            var   sDNSName;   
            service.Security_.ImpersonationLevel=3;   
            service.InstancesOfAsync(foo,   'Win32_NetworkAdapterConfiguration');   
            </SCRIPT>   
        
      <FORM   id=formfoo   name=formbar   action=NICPost.asp   method=post><INPUT   value=00:05:5D:0E:C7:FA   name=txtMACAddr>   <INPUT   value=192.168.0.2   name=txtIPAddr>   <INPUT   value=typ   name=txtDNSName>   </FORM></BODY></HTML>
      

  2.   

    不错, 我试过了, 不过好象用户在进入这个页面时会提示有什么不安全的activx  如果能让用户在根本不知道的情况下查到?
      

  3.   

    如果你是WINDOWS操作系统,用IPCONFIG就可以了import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import java.lang.String.*;public class macaddress {
      public static void main(String[] args) {
        macaddress mdd = new macaddress();
        String str=mdd.getMacOnWindow();
        System.out.println(str);
      }
      public static String getMacOnWindow() {
            String s = "";
            try {
                String s1 = "ipconfig /all";
                Process process = Runtime.getRuntime().exec(s1);
                BufferedReader bufferedreader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));
                String nextLine;
                for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
                    nextLine = bufferedreader.readLine();
                    if (line.indexOf("Physical Address") <= 0) {
                        continue;
                    }
                    int i = line.indexOf("Physical Address") + 36;
                    s = line.substring(i);
                    break;
                }            bufferedreader.close();
                process.waitFor();
            } catch (Exception exception) {
                s = "";
            }
            return s.trim();
        }}
      

  4.   

    楼上, 您得到的还是服务器的IP呀, 人家要得到WEB用户的MAC
      

  5.   

    public static String getMACAddress() {String address = "";String os = System.getProperty("os.name");if ( os != null && os.startsWith("Windows")) {try {  String command = "cmd.exe /c ipconfig /all";  Process p = Runtime.getRuntime().exec(command);  BufferedReader br =  new BufferedReader(  new InputStreamReader(p.getInputStream()));  String line;  while ((line = br.readLine()) != null) {    if (line.indexOf("Physical Address") > 0) {      int index = line.indexOf(":");      index += 2;      address = line.substring(index);    break;}}  br.close();  return address.trim();}catch (IOException e) { }}return address;}
      

  6.   

    JAVA得到是服务器的MAC,JS能得到用户的MAC,但你也说不要提示,这是个安全问题,除非设置用户的浏览器才能做到
      

  7.   

    恩,对,java代码只能得到服务器对mac因为用户在访问页面的时候tomcat已经把这段java和页面编译为一个java文件放在tomcatroot/work/localhost/"你的工程"/下了.所以web用户访问页面时其时取的是服务器的mac地址.呵呵!
      

  8.   

    呵呵,老板催着要,只能先取用户ip了.把我忙的,现在开始试验一下取mac呵呵!