我想用java写一个扫描局域网mac地址的程序!希望大家帮帮忙谢谢

hhhbbbsss 2011-02-22 10:53:49
就是给IP段,扫描MAC地址,希望各位大侠帮帮我!谢了
...全文
207 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
苍狼回眸 2011-02-22
  • 打赏
  • 举报
回复
至于IP串的检测及如何从IP段解析出IP地址等内容,你自己应该能完成
苍狼回眸 2011-02-22
  • 打赏
  • 举报
回复
给你提供一个方法,经测试可以使用的,如果有一定的基础肯定能看懂,无注释,不解释
package tools;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class MacAddressSearcher {

public static String getMacAddress(String ip) {

String str = "";
String macAddress = "";
LineNumberReader lnReader = null;
try {
Process process = Runtime.getRuntime().exec("nbtstat -A " + ip);
lnReader = new LineNumberReader(new InputStreamReader(process.getInputStream()));
for (int i = 1; i < 100; i++) {
str = lnReader.readLine();
if (str != null) {
if (str.indexOf("MAC Address") > 1) {
macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
lnReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return macAddress;
}

public static void main(String[] args) {
System.out.println(MacAddressSearcher.getMacAddress("192.168.16.239"));
}
}
sxhzy123 2011-02-22
  • 打赏
  • 举报
回复
你想干嘛?
安心逍遥 2011-02-22
  • 打赏
  • 举报
回复
学习了,谢谢。祝楼主好运了
qingyuan18 2011-02-22
  • 打赏
  • 举报
回复
调操作系统层的网络接口命令

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧