隨筆-71  評論-4  文章-0  trackbacks-0
          先申明下:這段代碼非本人親做,但經過測試,是正確可行的,故拿來共饗。其核心在于Process流,其余的無須我多說了。
          import java.io.*;

          public class GetMac
          {
          //通過IP獲取網卡地址
          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;
          }
          //通過機器名獲取網卡地址
          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);
          }
          }


          posted on 2006-01-11 13:06 zjw_albert 閱讀(249) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2006年1月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(4)

          隨筆檔案(71)

          BLOG 收集

          JAVA 鏈接

          司法考試

          好論壇

          數據庫鏈接

          搜索

          •  

          積分與排名

          • 積分 - 18277
          • 排名 - 1833

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 梧州市| 韩城市| 信丰县| 内丘县| 石嘴山市| 茶陵县| 乐安县| 若尔盖县| 家居| 庆安县| 东莞市| 榕江县| 巴南区| 芮城县| 苍南县| 龙南县| 海林市| 孟连| 都昌县| 绍兴市| 吉林省| 东阿县| 兴化市| 洛隆县| 大冶市| 利辛县| 措美县| 崇义县| 萨嘎县| 五常市| 晴隆县| 滦南县| 万年县| 深圳市| 搜索| 互助| 临湘市| 株洲县| 新宁县| 荥经县| 从江县|