我爱Aspx >> Asp.Net >> 使用C#调用外部Ping命令获取网络连接情况static void Main(string[] args)
{
string ip = "192.192.132.229";
string strRst = CmdPing(ip);
Console.WriteLine(strRst);
Console.ReadLine();
}
private static string CmdPing(string strIp)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string pingrst;
p.Start();
p.StandardInput.WriteLine("ping -n 1 "+strIp);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
if(strRst.IndexOf("(0% loss)")!=-1)
pingrst = "连接";
else if( strRst.IndexOf("Destination host unreachable.")!=-1)
Ҷƪл˵?
使用C#控制远程计算机的服务[05-20]
使用C#编写的一个定时关机程序[05-20]
C#处理鼠标和键盘事件[05-20]
使用C#实现阿拉伯数字到大写中文..[05-20]
C#如何取硬件标志[05-20]
用C#快速往Excel写数据[05-20]
c# 获得局域网主机列表实例[05-20]
c# 获得局域网主机列表实例[05-20]
用C#的Raw Socket实现网络封包监..[05-20]
利用C#实现标准的 Dispose模式[05-20]
使用C#控制远程计算机的服务[05-20]
使用C#编写的一个定时关机程序[05-20]
得到系统进程和结束某个指定的进..[05-20]
C#处理鼠标和键盘事件[05-20]
使用C#实现阿拉伯数字到大写中文..[05-20]
C#如何取硬件标志[05-20]
用C#快速往Excel写数据[05-20]
c# 获得局域网主机列表实例[05-20]
c# 获得局域网主机列表实例[05-20]
用C#的Raw Socket实现网络封包监..[05-20]