在asp.net(c#)下實(shí)現(xiàn)ping功能
添加引用:
using System.Diagnostics;
程序代碼:
string hostname = "http://www.baidu.com";
Process prc=new Process();
prc.StartInfo.FileName="cmd.exe";
prc.StartInfo.UseShellExecute=false;
prc.StartInfo.RedirectStandardInput = true;
prc.StartInfo.RedirectStandardOutput = true;
prc.StartInfo.RedirectStandardError = true;
prc.StartInfo.CreateNoWindow = false;
prc.Start();
prc.StandardInput.WriteLine("ping " + hostname);
prc.StandardInput.Close();
Response.Write(prc.StandardOutput.ReadToEnd());
執(zhí)行結(jié)果:
Microsoft Windows 2000 [Version 5.00.2195] (C) 版權(quán)所有 1985-2000 Microsoft Corp. C:\WINNT\system32>ping http://www.baidu.com Pinging http://www.baidu.com [59.37.71.86] with 32 bytes of data: Reply from 59.37.71.86: bytes=32 time=11ms TTL=59 Reply from 59.37.71.86: bytes=32 time=11ms TTL=59 Reply from 59.37.71.86: bytes=32 time=11ms TTL=59 Reply from 59.37.71.86: bytes=32 time=12ms TTL=59 Ping statistics for 59.37.71.86: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 11ms, Maximum = 12ms, Average = 11ms C:\WINNT\system32>
原創(chuàng)文章轉(zhuǎn)載請(qǐng)注明:文章轉(zhuǎn)載自 記憶盒子 [http://m.gazebo2go.com/blog/]
本文地址:http://m.gazebo2go.com/blog/archives/aspnet-csharp-execute-ping.html