java实现ping
发布网友
发布时间:2024-09-29 03:06
我来回答
共1个回答
热心网友
时间:13小时前
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;iaddrs.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());
}
}
}
}
}