c语言实现ping多个ip,[求助]如何实现C#循环ping多个IP,急!!

using System;

using System.Collections.Generic;

using

using System.Data;

using System.Diagnostics;

using System.Drawing;

using System.Text;

using System.Threading;

using System.Windows.Forms;

namespace WindwosLink

{

public partial class Form1 : Form

{

public static int updatetime;

public static bool fay = true;

public Thread thread;

public Form1()

{

InitializeComponent();

Button.CheckForIllegalCrossThreadCalls = false;

toolStripStatusLabel1.Text = "登陆时间:"+DateTime.Now.ToString();

toolStripStatusLabel2.Text = "技术支持QQ:492581728";

}

private void btnstart_Click(object sender, EventArgs e)

{

thread = new Thread(Deal);

thread.Start();

}

public void Deal()

{

btnstart.Enabled = false;

btnstop.Enabled = true;

updatetime = DateTime.Now.Minute;

while (fay)

{

Thread.Sleep(Convert.ToInt32(tbtime.Text.Trim()) * 60);

int newtime = DateTime.Now.Minute;

int result = newtime - updatetime;

if (result > Convert.ToInt32(tbtime.Text.Trim()))

{

CmdPing(tbip.Text.Trim());

}

if (result > 0)

{

CmdPing(tbip.Text.Trim());

updatetime = newtime;

}

}

}

//string ip = "211.102.90.6";

//string strRst = CmdPing(ip);

//Console.WriteLine(strRst);

//Console.ReadLine();

private void 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();

int abc = strRst.IndexOf("(0% 丢失)");

if (strRst.IndexOf("(0% 丢失)") != -1)

pingrst = "连接";

else if (strRst.IndexOf("Destination host unreachable.") != -1)

pingrst = "无法到达目的主机";

else if (strRst.IndexOf("请求超时。") != -1)

{

pingrst = "超时";

btnstart.Enabled = true;

btnstop.Enabled = false;

labmessage.Text = "请求超时,请尽快处理!!!";

labmessage.ForeColor = Color.Red;

fay = false;

bool result = PostMsgHelper.sendSms(tbphone.Text.Trim(), "您的服务器IP是:" + tbip.Text + "" + pingrst + "");

thread.Abort();

//MessageBox.Show("当前监控的服务器出现异常!!!");

}

else if (strRst.IndexOf("Unknown host") != -1)

pingrst = "无法解析主机";

else

pingrst = strRst;

p.Close();

//return pingrst;

}

6f83fddf9cb9ff6843fffd45e1807199.gif

59izk,com神奇百货,神奇百货网官网,shenqi,一个神奇的导购站!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值