java中可以获取默认网关IP和MAC地址吗?

发布于 2024-10-25 09:00:18 字数 62 浏览 9 评论 0原文

我正在尝试找到一种方法,从要在网站上运行的 java 小程序访问默认网关的 IP 和 MAC 地址,这可能吗?

I'm trying to find a way to access the IP and MAC addresses for the default gateway from a java applet to be run on a website, is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧瑾黎汐 2024-11-01 09:00:18

你不能在Java中做这种事情,比如得到Wifi 网络上的 SSID。这种低级硬件信息无法在 Java 中以跨平台的方式获取,并且 Java 只允许您在传输 (TCP) 级别工作,即使用套接字。

如果您需要此类信息,请尝试使用 Runtime.getRuntime().exec(...) 调用操作系统命令工具并解析输出。但是您必须处理不同的操作系统,这意味着不同的命令工具和输出。

但在 Applet 世界中,您无法调用操作系统命令工具,也无法打开文件,您处于沙箱中,该沙箱阻止 Applet 执行一些可能会给用户计算机带来风险的低级任务。

如果您签署了小程序,您就有权像常规桌面应用程序一样执行相同的操作,但这超出了范围。

尝试将问题集中在另一个方向。

You can't do that kind of thing in Java, like getting the SSID on a Wifi network. This low-level hardware information can not be obtained in Java in a cross-platform way and Java only allow you to work in the Transport (TCP) level, aka use sockets.

If you need this kind of information, try invoking a OS command tool using Runtime.getRuntime().exec(...) and parsing the output. But you have to deal with different OS that means different commands tools and outputs.

But in the Applet world, you can't invoke OS command tools, nor opening files, you are in a sandbox that prevents Applets for doing some low-levels tasks that can put in risk the user computer.

If you sign your applet, you have privileges to perform same operations like regular desktop applications, but this is out of scope.

Try to focus you problem in another direction.

孤独患者 2024-11-01 09:00:18

您可以使用类 java.net.NetworkInterface 中的方法 getHardwareAddress 获取 Java 中接口的 Mac 地址 (http://download.oracle.com/javase/6/docs/api/java /net/NetworkInterface.html#getHardwareAddress())。我不确定这是否会在 Applet 中起作用,而且我自己也从未测试过该方法,但如果有什么方法可以做到这一点,那么这个方法就是那个东西。

You can get the Mac Address of an interface in Java using the method getHardwareAddress in the class java.net.NetworkInterface (http://download.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html#getHardwareAddress()). I am not sure if that will work inside an Applet, and I have never tested that method myself, but if something does it, this method is that thing.

荒人说梦 2024-11-01 09:00:18

IP 地址?当然。只需让小程序连接回您的服务器即可。小程序可以打开到托管它的服务器的 http 连接。

MAC 和默认 GW 是系统特定的东西,您可以通过外部程序获得这些东西,但我不能 100% 确定这些在小程序沙箱中受支持(事实上,它们可能不受支持)。

The IP Address? sure thing. Just have the applet connect back to your server. An applet can open an http connection to the server that hosts it.

The MAC and Default GW are system specific things you could get via external programs, but I'm not 100% sure those are supported in the applet sandbox (in fact, they're probably not supported).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文