你如何使用Java获得以太网地址? [英] How do you get the ethernet address using Java?

查看:179
本文介绍了你如何使用Java获得以太网地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索用于访问特定网站的网络接口的以太网地址。

I would like to retrieve the ethernet address of the network interface that is used to access a particular website.

如何在Java中完成此操作?

How can this be done in Java?

解决方案请注意, getHardwareAddress 的公认解决方案仅适用于Java 6.似乎是Java 5的解决方案,除了执行i(f | p)confing。

Solution Note that the accepted solution of getHardwareAddress is only available in Java 6. There does not seem to be a solution for Java 5 aside from executing i(f|p)confing.

推荐答案

java.net.NetworkInterface.getHardwareAddress (方法在Java中添加6)

java.net.NetworkInterface.getHardwareAddress (method added in Java 6)

必须在您感兴趣的机器上调用它 - MAC不会跨网络边界(即LAN和WAN)传输。如果你想在网站服务器上使用它来询问客户端,你必须运行一个小程序,它会将结果报告给你。

It has to be called on the machine you are interested in - the MAC is not transferred across network boundaries (i.e. LAN and WAN). If you want to make use of it on a website server to interrogate the clients, you'd have to run an applet that would report the result back to you.

For Java 5及更早版本我发现代码在各种系统上解析命令行工具的输出

For Java 5 and older I found code parsing output of command line tools on various systems.

这篇关于你如何使用Java获得以太网地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆