C#循环ping多个IP的问题 我想实现C#循环ping多个局域网IP的功能,每次ping的信息都显示在richTextBox中,就是在cmd->ping www.baidu.com出现的那种效果一样。现在ping一个IP的可以实现这样的功能。但是循环ping我就不知道应该怎么办了!!! 我把获取的多个IP保存在一个一维数组中,然后循环数组,读取IP,获取结果,不知道这个想法是不是合理? 哪位给指点一下,说下大体的思路好吗? 谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 [DllImport("kernel32.dll", EntryPoint = "WinExec")] public static extern int WinExec( string lpCmdLine, int nCmdShow ); private void button1_Click(object sender, EventArgs e) { WinExec("cmd.exe /C ping 192.168.1.1 >>C:\\a.TXT", 0); }Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StandardInput.WriteLine("ping 192.168.1.1"); p.StandardInput.WriteLine("exit"); string str = p.StandardOutput.ReadToEnd(); File.AppendAllText("c:\\a.txt", str); string[] ipList = { "192.168.1.1", "192.168.1.2" }; Dictionary<string, bool> dicPingResult = new Dictionary<string, bool>(); foreach (string ip in ipList) { using (Ping ping = new Ping()) { ping.SendAsync(ip, 1000, null); ping.PingCompleted += (sender, e) => { dicPingResult[e.Reply.Address.ToString()] = e.Reply.Status == IPStatus.Success; }; } } C# 读Excel日期转换问题 C#网站发布的问题~~~ 求救:关于C#曲线绘图的制作? C#的效率?? 如何输出Dictionary 所有的键 和值? 关于winform树控件带checkbox的问题!!急 关于messagebox的问题 郁闷的zoom和clip问题。哪位大神能解救俺~! 救命,怎么在程序中绑定Label?? 数据多表连接问题,请指教 大牛们啊.局域网版程序整成单机版都要考虑些什么问题啊?长长长长! DataGridViewComboBoxColumn绑定数据源后选中其中某项的问题
public static extern int WinExec(
string lpCmdLine,
int nCmdShow
);
private void button1_Click(object sender, EventArgs e)
{ WinExec("cmd.exe /C ping 192.168.1.1 >>C:\\a.TXT", 0);
}
Process p = new Process();
p.StartInfo.FileName = "cmd.exe"; p.StandardInput.WriteLine("ping 192.168.1.1");
p.StandardInput.WriteLine("exit");
string str = p.StandardOutput.ReadToEnd();
File.AppendAllText("c:\\a.txt", str);
string[] ipList = { "192.168.1.1", "192.168.1.2" };
Dictionary<string, bool> dicPingResult = new Dictionary<string, bool>();
foreach (string ip in ipList)
{
using (Ping ping = new Ping())
{
ping.SendAsync(ip, 1000, null);
ping.PingCompleted += (sender, e) =>
{
dicPingResult[e.Reply.Address.ToString()] = e.Reply.Status == IPStatus.Success;
};
}
}