`
michelecindy
  • 浏览: 173103 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

用JAVA做一个PING

    博客分类:
  • Java
阅读更多
package ceshi;

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);
		}
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics