当前位置: 代码迷 >> J2SE >> 求教 InetAddress中isReachable()总是返回false,该怎么处理
  详细解决方案

求教 InetAddress中isReachable()总是返回false,该怎么处理

热度:35   发布时间:2016-04-23 19:58:15.0
求教 InetAddress中isReachable()总是返回false
用ping可以通百度绝笔没问题 但是用java就是连不上  总是false

图:http://g.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=4dcbd987f303918fd78435cc610d0aaf/c995d143ad4bd1135d1c39555eafa40f4afb0587.jpg

网上和API都说防火墙和服务器配置可能会导致阻塞
防火墙关了还是连不上


图:http://h.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=2cd04b736f600c33f02cd6ce2a7c7d37/f703738da9773912f4a80d06fc198618377ae2cf.jpg

服务器配置不会弄 都不知道什么服务器 怎么配置求教.



就是怎么样才能连上获取到的ip 让isReachable()返回true

再说明下: 不止网络ip连不上  局域网ip也没法连上 
求指点了
------解决思路----------------------
按原理这个方法和ping应该同等效果~ 会不会是 不是同一块网卡?
你这么试试:isReachable(3000)
------解决思路----------------------
1. isReacheable你用的哪个参数啊?TTL是什么?
2. 网络的ICMP开了么?
------解决思路----------------------
Test whether that address is reachable. Best effort is made by the implementation to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtainedotherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host.

红字部分的意思是,如果本机的权限允许,那么isReachable采用跟PING一样的方式取连接远程服务器。
但是默认情况下,你绝逼没有这个权限。

蓝字部分的意思是,要是没有权限,那么尝试TCP连接远程服务器的7号端口。所以,如果你能够telnet ip 7成功的话,isReachable返回就是true了。
  相关解决方案