简体   繁体   English

用Java打开带有IP地址的网页

[英]Open a web page with IP Address in Java

In my program, the user can open a web page using his default browser. 在我的程序中,用户可以使用其默认浏览器打开网页。 But what I possess is the IP address of the machine and not its URL . 但是我拥有的是机器的IP地址,而不是它的URL

I found out that a web page can be easly opened with: 我发现可以轻松地打开网页:

java.awt.Desktop.getDesktop().browse(uri);

but browse accept URI object. browse接受URI对象。 Even a conversion URL-IP address is not a solution because I don't know what machine's URI is, I've only its IP-Address. 即使转换URL-IP地址也不是解决方案,因为我不知道什么机器的URI,我只有它的IP地址。 So, is there a way to open a web page passing its IP address? 那么,有没有办法打开一个通过其IP地址的网页? Thank you a lot! 非常感谢!

If the IP is publically accessible (the host is not behind the NAT) you can replace the host name by the IP address in the URI. 如果IP可公开访问(主机不在NAT后面),则可以用URI中的IP地址替换主机名。

One possible thing that can mess it up is that in your client machine in etc/hosts file the hostname is mapped to some other IP address. 可能使它混乱的一件事是,在客户机中的etc/hosts文件中,主机名已映射到其他IP地址。

You might want to check this question to better understand how hostname to IP resolution works. 您可能需要检查此问题,以更好地了解IP解析主机名的工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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