请问下:java下判断网络是是否连通的思路

eve_zz 2010-04-11 12:16:19
除了用ping命令外,还有其他什么方法呢
...全文
277 5 打赏 收藏 转发到动态 举报
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
java 中有 ping 么?

可以建立 Socket 连接网络就是通的,否则就是不通的。
luffyke 2010-04-11
  • 打赏
  • 举报
回复
Java可以执行ping的,用套接字也行!
ilrxx 2010-04-11
  • 打赏
  • 举报
回复
		   Runtime  runtime  =  Runtime.getRuntime();  
Process process =null;
String line=null;
InputStream is =null;
InputStreamReader isr=null;
BufferedReader br =null;
String ip="www.sna.com.cn"; //待Ping的地址
try
{
process =runtime.exec("ping "+ip);
is = process.getInputStream();
isr=new InputStreamReader(is);
br =new BufferedReader(isr);
while( (line = br.readLine()) != null )
{
System.out.println(line);
System.out.flush();
}
is.close();
isr.close();
br.close();
}
catch(IOException e )
{
System.out.println(e);
runtime.exit(1);
}
ilrxx 2010-04-11
  • 打赏
  • 举报
回复
可以用Runtime直接执行dos命令,linux系统的话,直接执行shell也可以
eve_zz 2010-04-11
  • 打赏
  • 举报
回复
用java.net.InetAddress类中的

public boolean isReachable(int timeout) throws IOException

这个方法即可。
相关推荐

62,569

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告