C#循环ping多个IP的问题

gaoxing_1985007 2010-09-08 09:19:10
我想实现C#循环ping多个局域网IP的功能,每次ping的信息都显示在richTextBox中,就是在cmd->ping www.baidu.com出现的那种效果一样。现在ping一个IP的可以实现这样的功能。但是循环ping我就不知道应该怎么办了!!!

我把获取的多个IP保存在一个一维数组中,然后循环数组,读取IP,获取结果,不知道这个想法是不是合理?

哪位给指点一下,说下大体的思路好吗?

谢谢!!!
...全文
410 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
freefei 2010-09-09
  • 打赏
  • 举报
回复
关注!!
gaoxing_1985007 2010-09-08
  • 打赏
  • 举报
回复
是的,局域网同一个网段内的

[Quote=引用 1 楼 csrwgs 的回复:]
引用楼主 gaoxing_1985007 的回复:
多个IP保存在一个一维数组中


局域网吗?
[/Quote]
bloodish 2010-09-08
  • 打赏
  • 举报
回复

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;
};
}
}
wuyq11 2010-09-08
  • 打赏
  • 举报
回复
[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);

csrwgs 2010-09-08
  • 打赏
  • 举报
回复
[Quote=引用楼主 gaoxing_1985007 的回复:]
多个IP保存在一个一维数组中
[/Quote]

局域网吗?

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧