如何使用java程序检测互联网连接(How to detect internet connectivity using java program)

编程入门 行业动态 更新时间:2024-10-28 05:15:54
如何使用java程序检测互联网连接(How to detect internet connectivity using java program)

如何编写一个java程序,告诉我我是否可以上网。 我不想ping或创建与某些外部URL的连接,因为如果该服务器将关闭,那么我的程序将无法工作。 我想要可靠的方法来检测哪些信息会告诉我100%保证无论我的操作系统是否具有互联网连接。 我想要直接连接到互联网的计算机的程序。

我已经尝试过下面的程序

URL url = new URL("http://www.xyz.com/"); URLConnection conn = url.openConnection(); conn.connect();

我想要比这个程序更适合的东西

感谢Sunil Kumar Sahoo

How to write a java program which will tell me whether I have internet access or not. I donot want to ping or create connection with some external url because if that server will be down then my program will not work. I want reliable way to detect which will tell me 100% guarantee that whether I have internet connection or not irrespective of my Operating System. I want the program for the computers who are directly connected to internet.

I have tried with the below program

URL url = new URL("http://www.xyz.com/"); URLConnection conn = url.openConnection(); conn.connect();

I want something more appropriate than this program

Thanks Sunil Kumar Sahoo

最满意答案

这取决于你的意思是“互联网”连接。 许多计算机没有直接连接到互联网,所以即使你可以检查他们是否有网络连接,这并不意味着他们可以访问互联网

测试计算机是否可以访问其他服务器的唯一100%可靠方法是实际尝试。

It depends on what you mean by "internet" connection. Many computers are not connected directly to the internet, so even if you could check whether they have a network connection, it doesn't always mean they can access the internet.

The only 100% reliable way to test whether the computer can access some other server is to actually try.

更多推荐

本文发布于:2023-08-04 15:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:互联网   如何使用   程序   java   program

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!