Java 从PING扫描中检索MAC地址
我开发了一个代码,使我能够ping一系列IP地址。ping扫描的结果确定了哪些本地计算机是可访问的,如果可以访问,还有主机名是否不可访问 我目前在检索可访问IP地址的MAC地址时遇到问题。有人能解决这个问题吗Java 从PING扫描中检索MAC地址,java,ping,ethernet,Java,Ping,Ethernet,我开发了一个代码,使我能够ping一系列IP地址。ping扫描的结果确定了哪些本地计算机是可访问的,如果可以访问,还有主机名是否不可访问 我目前在检索可访问IP地址的MAC地址时遇到问题。有人能解决这个问题吗 package networkping; import java.io.IOException; import java.net.InetAddress; /** * * @author Learner */ public class Networkping { public st
package networkping;
import java.io.IOException;
import java.net.InetAddress;
/**
*
* @author Learner
*/
public class Networkping {
public static void main(String[] args) throws IOException {
InetAddress localhost = InetAddress.getLocalHost();
// this code assumes IPv4 is used
byte[] ip = localhost.getAddress();
for (int i = 1; i <= 254; i++)
{
ip[3] = (byte)i;
InetAddress address = InetAddress.getByAddress(ip);
if (address.isReachable(1000))
{
System.out.println(address + " Address is reachable" );
}
else if (!address.getHostAddress().equals(address.getHostName()))
{
System.out.println(address + " Address is known in a DNS lookup and is reachable ");
}
else
{
System.out.println(address + " Address is unreachable");
}
}
}
包联网;
导入java.io.IOException;
导入java.net.InetAddress;
/**
*
*@作者学习者
*/
公共类网络{
公共静态void main(字符串[]args)引发IOException{
InetAddress localhost=InetAddress.getLocalHost();
//此代码假定使用了IPv4
字节[]ip=localhost.getAddress();
对于(inti=1;i,您不能仅使用java来实现这一点
有两种选择:
- 通过java执行另一个进程,并通过标准输出与原始java应用程序通信。例如,
ARP
- 按照注释中的建议使用JNI
请参阅以下参考资料/答案:
第二个资源甚至有一个调用ARP的实现方法,名为私有字符串getMac(stringip)
仅使用java无法做到这一点
有两种选择:
- 通过java执行另一个进程,并通过标准输出与原始java应用程序通信。例如,
ARP
- 按照注释中的建议使用JNI
请参阅以下参考资料/答案:
第二个资源甚至有一个名为private String getMac(String ip)的调用ARP的实现方法
不幸的是,没有JNI,Java无法做到这一点,这取决于网络配置/OS,可能根本无法做到。@Hexafrance感谢您的评论和输入,但我一直将此作为作业,导师向我保证,可以do@user3071069看看我答案中的链接。这是可能的,但你需要绕圈不幸的是,没有JNI,Java就无法做到这一点,这取决于网络配置/操作系统,可能根本无法做到。@Hexafrance感谢您的评论和输入,但我一直将此作为作业,导师向我保证do@user3071069看看我答案中的链接。这是可能的,但你需要绕道而行一路走来。