Corp./r/n/r/nD://himuraz//csharpproject//ZZ//ConsoleTest//bin//Debug>ping -n 1
192.192.132.231/r/n/r/r/nPinging 192.192.132.231 with 32 bytes of data:/r/r/n/r/r/nReply from 192.192.132.231: bytes=32 time<10ms TTL=128/r/r/n/r/r/nPing statistics for
192.192.132.231:/r/r/n Packets: Sent = 1, Received = 1, Lost = 0 (0%
loss),/r/r/nApproximate round trip times in milli-seconds:/r/r/n Minimum = 0ms, Maximum = 0ms, Average =
0ms/r/r/n/r/nD://himuraz//csharpproject//ZZ//ConsoleTest//bin//Debug>exit/r/n"
有了输出结果,那还有什么好说的,分析strRst字符串就可以知道网络的连接情况了。
下面是一个完整的程序,当然对Ping.exe程序执行的结果不全,读者可以进一步修改, 完整代码如下:
view plaincopy to clipboardprint? 1. using System;
2. using System.Diagnostics;
3. namespace ZZ
4. {
5. class ZZConsole
6. {
7. [STAThread]
8. static void Main(string[] args)
9. {
10. string ip = "192.192.132.229";
11. string strRst = CmdPing(ip);
12. Console.WriteLine(strRst);
13. Console.ReadLine();
14. }
15. private static string CmdPing(string strIp)
16. {
17. Process p = new Process();
18. p.StartInfo.FileName = "cmd.exe";
19. http://www.77cn.com.cneShellExecute = false;
20. p.StartInfo.RedirectStandardInput = true;
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C# 网络连接判断(2)在线全文阅读。
相关推荐: