首页 > 学院 > 编程设计 > 正文

java实现ping

2020-07-14 13:41:25
字体:
来源:转载
供稿:网友
import java.io.*;
import java.lang.*;
public class Ping{

public Ping() {
}
public static void main(String args[])
{
String[] addrs= {"www.sina.com"};
if (addrs.length < 1)
{
System.out.println("syntax Error!");
}
else
{
for(int i=0;i<addrs.length;i++){
String line = null;
try
{
Process pro = Runtime.getRuntime().exec("ping " + addrs[i]);
BufferedReader buf = new BufferedReader(new InputStreamReader(pro.getInputStream()));
while((line = buf.readLine()) != null)
System.out.println(line);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表