winform根据cmd获取网络ping值
来源:互联网 发布:火源计划激活码淘宝 编辑:程序博客网 时间:2024/05/16 05:52
/// <summary>
/// 测试网络连通性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TestContinuity(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TestUrltex.Text))
{
label10.Visible = true;//pinglabel
label11.Visible = true;//pinglabel
//获取ping值 时间=36ms
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;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + TestUrltex.Text);
p.StandardInput.WriteLine("exit");
string stre = p.StandardOutput.ReadToEnd();
if (stre.IndexOf("(0%loss)") != -1)
{
label11.ForeColor = System.Drawing.Color.LawnGreen;
label11.Text = "连接";
}
else if (stre.IndexOf("Destination host unreachable.") != -1 || stre.IndexOf("传输失败") > -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "无法达到目的的主机";
}
else if (stre.IndexOf("Request timed out.") != -1 || stre.IndexOf("请求超时") > -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "超时";
}
else if (stre.IndexOf("Unknown host") != -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "无法解析主机";
}
else if (stre.IndexOf("Ping 请求找不到主机") > -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "请求找不到主机";
}
else if (stre.IndexOf("往返行程的估计时间") > -1)
{
label11.ForeColor = System.Drawing.Color.LawnGreen;
string ms = stre.Substring(stre.IndexOf("时间=") + 3, 3);
if (ms.Contains("m")) { ms = ms.Replace("m", ""); }
label11.Text = ms + "ms";
}
else
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "未知错误";
Log("请检查‘网站路径’!");
}
p.Close();
}
else
{
label10.Visible = false;
label11.Visible = false;
Log("请输入‘网站路径’!");
}
}
/// 测试网络连通性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TestContinuity(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TestUrltex.Text))
{
label10.Visible = true;//pinglabel
label11.Visible = true;//pinglabel
//获取ping值 时间=36ms
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;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + TestUrltex.Text);
p.StandardInput.WriteLine("exit");
string stre = p.StandardOutput.ReadToEnd();
if (stre.IndexOf("(0%loss)") != -1)
{
label11.ForeColor = System.Drawing.Color.LawnGreen;
label11.Text = "连接";
}
else if (stre.IndexOf("Destination host unreachable.") != -1 || stre.IndexOf("传输失败") > -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "无法达到目的的主机";
}
else if (stre.IndexOf("Request timed out.") != -1 || stre.IndexOf("请求超时") > -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "超时";
}
else if (stre.IndexOf("Unknown host") != -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "无法解析主机";
}
else if (stre.IndexOf("Ping 请求找不到主机") > -1)
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "请求找不到主机";
}
else if (stre.IndexOf("往返行程的估计时间") > -1)
{
label11.ForeColor = System.Drawing.Color.LawnGreen;
string ms = stre.Substring(stre.IndexOf("时间=") + 3, 3);
if (ms.Contains("m")) { ms = ms.Replace("m", ""); }
label11.Text = ms + "ms";
}
else
{
label11.ForeColor = System.Drawing.Color.Red;
label11.Text = "未知错误";
Log("请检查‘网站路径’!");
}
p.Close();
}
else
{
label10.Visible = false;
label11.Visible = false;
Log("请输入‘网站路径’!");
}
}
阅读全文
0 0
- winform根据cmd获取网络ping值
- Winform-根据当前IP获取所在城市名称
- PHP 获取PING值
- 使用C#调用Ping命令获取网络连接情况 + 获取DOS返回值
- TruePing vs. cmd ping
- cmd命令---ping!
- C# WinForm 获取 http 网络图片
- ping网络
- 根据图片的网络URL获取Bitmap
- 根据传入的地址获取网络文件大小
- 根据网络状态获取Ip地址
- 根据网络接口名获取IP地址
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- tensorflow简单实现卷积前向过程
- TypeArray、ArrayBuffer、Blob、File、DataURL、canvas的相互转换
- SSH反向隧道进行内网穿透
- ls -l命令详解(转)
- 微信小程序图表插件(wx-charts)
- winform根据cmd获取网络ping值
- bootstrap-select清除选中的状态,恢复默认状态
- ATL::CComPtr::operator& 断言 Expression: p == 0 原因分析
- 【微信支付】HTTPS服务器配置
- hjr教程-JavaScript(三):springmvc+mongodb+angular.js搭建网站后台
- PHP判断手机是IOS还是Android
- Tensorflow项目实现汇总(不断更新...)
- STL vector 源码解析
- 第一个Struts2项目(上)