首页 > 开发 > Java > 正文

java实现ping

2024-07-16 17:44:58
字体:
来源:转载
供稿:网友
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());
}
}
}
}
}

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