Java Votary

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            48 隨筆 :: 1 文章 :: 80 評論 :: 0 Trackbacks

          方法一:

          調(diào)用Windows的DOS命令,從輸出結(jié)果中讀取MAC地址:

          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;
          }

          We can replace the "ipconfig" to "ping x.x.x.x" and "arp -a"...We can get the mac list...haha!!

          缺點(diǎn):只能取得服務(wù)器端MAC地址.如果要取得客戶端的MAC地址,需用Applet.只針對MS-WIN系統(tǒng).

           

          方法二:

          可以用JS或vbscript來調(diào)用WMI接口來獲取Client端的MAC地址.


           
           
           
           
           
           
           
            
            

            
            

            


            

             
             
             

            
           

          忘了附上原文的出處了:
          How to get IP address of the browser when its operating behind a proxy/firewall? (applets...activex....??)
          http://www.faqts.com/knowledge_base/view.phtml/aid/9005/fid/125

          關(guān)于WMI的詳細(xì)信息可以參看MSDN:
          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks_for_scripts_and_applications.asp

          平心而論,WMI的很強(qiáng)大的。原先需要動用重量級編程工具才能做到的事,現(xiàn)在用js/vbscript就可以做了。

          獲取多塊網(wǎng)卡的MAC地址:

          if(objObject.MACAddress != null && objObject.MACAddress != "undefined"){
                                   MACAddr = objObject.MACAddress;
                                   alert( MACAddr );
                             }

          缺點(diǎn):需要ActiveX支持.對MS-WIN系統(tǒng)有效.

          方法三:

          想137口發(fā)送UDP查詢:

          WINDOWS平臺的客戶端(當(dāng)獲取時它轉(zhuǎn)換為服務(wù)端角色),NETBIOS協(xié)議在137口上,我們只要向它的137口發(fā)送UDP查詢,獲取它的返回值就可以獲取到它所有的網(wǎng)卡地址.

          以上內(nèi)容來自dev2dev的討論帖:

          http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=12941&tstart=0

           

          posted on 2005-01-20 08:50 eamoi 閱讀(636) 評論(1)  編輯 收藏 收藏至365Key 所屬分類: Java

          評論: # Java系統(tǒng)如何獲取客戶端的MAC地址? [TrackBack] 2005-01-20 11:01 | eamoi
          Ping Back來自:blog.csdn.net
          eamoi引用了該文章,地址:http://blog.csdn.net/eamoi/archive/2005/01/20/260611.aspx
          posted on 2005-11-23 20:33 Dion 閱讀(9768) 評論(3)  編輯  收藏 所屬分類: Java

          評論

          # re: [收藏]如何獲取客戶端MAC地址 2007-03-29 12:28 joyce
          import java.io.*;

          public class GetMac
          {
          //通過IP獲取網(wǎng)卡地址
          private String getMacAddressIP(String remotePcIP){
          String str="";
          String macAddress="";
          try {
          Process pp= Runtime.getRuntime().exec ("nbtstat -A " + remotePcIP);
          InputStreamReader ir = new InputStreamReader(pp.getInputStream());
          LineNumberReader input = new LineNumberReader (ir);
          for (int i = 1; i <100; i++)
          {
          str=input.readLine();
          if (str!=null)
          {
          if(str.indexOf("MAC Address")>1)
          { macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
          break;
          }
          }
          }
          }
          catch (IOException ex) {}
          return macAddress;
          }
          //通過機(jī)器名獲取網(wǎng)卡地址
          private String getMacAddressName(String remotePcIP){
          String str="";
          String macAddress="";
          try {
          Process pp= Runtime.getRuntime().exec ("nbtstat -a " + remotePcIP);
          InputStreamReader ir = new InputStreamReader(pp.getInputStream());
          LineNumberReader input = new LineNumberReader (ir);
          for (int i = 1; i <100; i++)
          {
          str=input.readLine();
          if (str!=null)
          {
          if(str.indexOf("MAC Address")>1)
          { macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
          break;
          }
          }
          }
          }
          catch (IOException ex) {}
          return macAddress;
          }
          public static void main(String[] args)
          {
          GetMac getmac;
          getmac=new GetMac();
          String mac="";
          mac=getmac.getMacAddressIP("192.168.0.18");//YOUR IP
          System.out.println(mac);
          mac=getmac.getMacAddressName("tom");// YOUR HOST-NAME
          System.out.println(mac);
          }
          }
            回復(fù)  更多評論
            

          # re: [收藏]如何獲取客戶端MAC地址 2008-09-11 22:17 tg54y
          <input type='text' value='奶子'/>  回復(fù)  更多評論
            

          # re: [收藏]如何獲取客戶端MAC地址 2009-11-02 21:17 愛愛愛
          樓主,請把成熟點(diǎn)的東西放上來,  回復(fù)  更多評論
            

          主站蜘蛛池模板: 根河市| 安丘市| 卢湾区| 峨边| 武邑县| 伊宁县| 彝良县| 陵水| 延寿县| 普定县| 兰坪| 福州市| 南郑县| 南和县| 林西县| 石家庄市| 二连浩特市| 峨山| 白河县| 同德县| 和政县| 萨迦县| 沛县| 泊头市| 大化| 杂多县| 永州市| 平顶山市| 永安市| 岳普湖县| 宁陕县| 阳高县| 雅江县| 邢台市| 永仁县| 临城县| 呼和浩特市| 南涧| 鄂伦春自治旗| 民乐县| 天津市|