如何用c#做一个ping 的软件呢! http://dotnet.aspx.cc/ShowDetail.aspx?id=VXMGWMHF-OJCC-4RBD-KH6X-RIJQLD17QMFW 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //检查网络连接 public static string CmdPing(string _strHost) { string m_strHost = _strHost; Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; string pingrst = string.Empty; process.StartInfo.Arguments = "ping " + m_strHost + " -n 1"; process.Start(); process.StandardInput.AutoFlush = true; string temp = "ping " + m_strHost + " -n 1" ; process.StandardInput.WriteLine(temp); process.StandardInput.WriteLine("exit"); string strRst = process.StandardOutput.ReadToEnd(); if(strRst.IndexOf("(0% loss)")!=-1) pingrst = "连接"; else if( strRst.IndexOf("Destination host unreachable.")!=-1) pingrst = "无法到达目的主机"; else if(strRst.IndexOf("Request timed out.")!=-1) pingrst = "超时"; else if(strRst.IndexOf("Unknown host")!=-1) pingrst = "无法解析主机"; else pingrst = strRst; process.Close(); return pingrst ; } Socket(AddressFamily.InterNetwork, SocketType.Raw,ProtocolType.Icmp);发送raw消息你去查查icmp协议,我记得type 8, code 0 DropDownList控件取值问题 c#转义字符问题 急,关于读取压缩文件的问题 奇怪问题,.net里一个HttpWebResponce里怎么多次Set-Cookie? C#类数据窗口问题 可不可以做成类似PB的FreeDatawindow或有什么好的解决方案 word 操作 一个JS转C#问题 100分求解 高分求助有关SQL问题,有请高手指教 送(100)分菜鸟问题-求救,怎么在C#中点击按纽打开本地一个可执行文件!! 数据库如何共用(在线等待)急!!!!!!!!!! 字符串的替换问题! 有谁碰到这样的错误?
public static string CmdPing(string _strHost)
{
string m_strHost = _strHost;
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
string pingrst = string.Empty;
process.StartInfo.Arguments = "ping " + m_strHost + " -n 1";
process.Start();
process.StandardInput.AutoFlush = true;
string temp = "ping " + m_strHost + " -n 1" ;
process.StandardInput.WriteLine(temp);
process.StandardInput.WriteLine("exit");
string strRst = process.StandardOutput.ReadToEnd();
if(strRst.IndexOf("(0% loss)")!=-1)
pingrst = "连接";
else if( strRst.IndexOf("Destination host unreachable.")!=-1)
pingrst = "无法到达目的主机";
else if(strRst.IndexOf("Request timed out.")!=-1)
pingrst = "超时";
else if(strRst.IndexOf("Unknown host")!=-1)
pingrst = "无法解析主机";
else
pingrst = strRst;
process.Close(); return pingrst ;
}
你去查查icmp协议,我记得type 8, code 0