110,570
社区成员
发帖
与我相关
我的任务
分享
//cdn1.txt中有131条ip记录
//ip记录格式192.168.1.1 www.baidu.com
private static void Main()
{
var sr = new StreamReader("cdn1.txt");
while (true)
{
string str = sr.ReadLine();
if (String.IsNullOrEmpty(str))
break;
PingFunc(str);
}
sr.Close();
Console.ReadLine();
}
private static void PingFunc(string str)
{
testping = new Ping();
string ip = str.Split(' ')[0];
testping.PingCompleted += PingSuccess;
testping.SendAsync(ip, 1000, str);
}
static void PingSuccess(object sender, PingCompletedEventArgs e)
{
lock (_lock)
{
string temp = e.UserState + "请求结果:" + e.Reply.Status + "(编号" + i + "),耗时:" + e.Reply.RoundtripTime + "ms";
result.AppendLine(temp);
StreamWriter sw = new StreamWriter("result.txt", true);
sw.WriteLine(temp);
sw.Close();
Console.WriteLine(temp);
}
}