Passing an argument to cmd.exe

前端 未结 5 1606
春和景丽
春和景丽 2020-12-01 20:47

I am attempting to ping a local computer from my C# program. To accomplish this, I\'m using the following code.

System.Diagnostics.ProcessStartInfo proc = ne         


        
5条回答
  •  情话喂你
    2020-12-01 21:18

    You could just use the System.Net.NetworkInformation.Ping class.

        public static int GetPing(string ip, int timeout)
        {
            int p = -1;
            using (Ping ping = new Ping())
            {
                    PingReply reply = ping.Send(_ip, timeout);
                    if (reply != null)
                        if (reply.Status == IPStatus.Success)
                            p = Convert.ToInt32(reply.RoundtripTime);
            }
            return p;
        }
    

提交回复
热议问题