用JAVA做一个PING

package com.kingsoft.main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Ping {

	public static void main(String[] args) {

		String ip = "www.sina.com.cn";
		String pingResult = "";

		String pingCmd = "ping " + ip;

		try {
			Runtime r = Runtime.getRuntime();
			Process p = r.exec(pingCmd);

			BufferedReader in = new BufferedReader(new InputStreamReader(p
					.getInputStream()));
			String inputLine;
			while ((inputLine = in.readLine()) != null) {
				System.out.println(inputLine);
				pingResult += inputLine;
			}
			in.close();

		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

你可能感兴趣的:(java)