开发者社区> 问答> 正文

怎么实现自动获取ip地址和mac地址

如何使用java代码自动获取计算机的ip地址和mac地址求java代码

展开
收起
蛮大人123 2016-02-21 10:58:47 3052 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public static 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;
     }
    2019-07-17 18:45:48
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
子网路由介绍 立即下载
探索连接的最后十秒”落时”的网关 立即下载
低代码开发师(初级)实战教程 立即下载