你如何检查你是否可以通过java连接到互联网?一种方法是:
final URL url = new URL("http://www.google.com");
final URLConnection conn = url.openConnection();
... if we got here, we should have net ...
Run Code Online (Sandbox Code Playgroud)
但是,是否有更适合执行该任务的东西,特别是如果您需要经常进行连续检查并且极有可能丢失互联网连接?
我可以用
ip = InetAddress.getLocalHost();
NetworkInterface.getByInetAddress(ip);
Run Code Online (Sandbox Code Playgroud)
获取mac地址,但是如果我在离线机器中使用此代码则不起作用.
那么,我怎样才能获得Mac地址?