在asp.net(c#)下实现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());
执行结果:
Microsoft Windows 2000 [Version 5.00.2195] (C) 版权所有 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>
原创文章转载请注明:文章转载自 记忆盒子 [http://www.webkaka.com/blog/]
本文地址:http://www.webkaka.com/blog/archives/aspnet-csharp-execute-ping.html
☉c#利用WebClient和WebRequest获取网页源代码的比较 (2009-7-15 13:28:21)
Liwen 于 2009-9-7 9:23:21 回复博客是个资料库,把一些东西记录下来,以便需要时查找.
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。