简体   繁体   中英

Is it possible to get the default gateway IP and MAC addresses in java?

我正在尝试找到一种方法来从一个java applet访问默认网关的IP和MAC地址,以便在网站上运行,这可能吗?

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.

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM