1
public static string CmdPing(string strIp)
2
{
3
4
Process p = new Process();
5
p.StartInfo.FileName = "cmd.exe";
6
p.StartInfo.UseShellExecute = false;
7
p.StartInfo.RedirectStandardInput = true;
8
p.StartInfo.RedirectStandardOutput = true;
9
p.StartInfo.RedirectStandardError = true;
10
p.StartInfo.CreateNoWindow = true;
11
string pingrst;
12
p.Start();
13
p.StandardInput.WriteLine("ping -n 1 " + strIp);
14
p.StandardInput.WriteLine("exit");
15
string strRst = p.StandardOutput.ReadToEnd();
16
if (strRst.IndexOf("(0% loss)") != -1)
17
pingrst = "连接";
18
else if (strRst.IndexOf("Destination host unreachable.") != -1)
19
pingrst = "无法到达目的主机";
20
else if (strRst.IndexOf("Request timed out.") != -1)
21
pingrst = "超时";
22
else if (strRst.IndexOf("Unknown host") != -1)
23
pingrst = "无法解析主机";
24
else
25
pingrst = strRst;
26
p.Close();
27
return pingrst;
28
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28
