当代码为RUN时,它必须对我指定的网站进行四次ping操作,然后将结果写入.csv文件。但我不断收到TIMEOUT错误。谁能告诉我为什么?我尝试了很多不同的东西,注意到目前为止工作。请帮助我。Ping一个网站并将数据保存在.csv文件中
static void Main(string[] args)
{
List<string> lstWebSites = new List<string>();
lstWebSites.Add("www.yahoo.com");
lstWebSites.Add("www.att.com");
lstWebSites.Add("www.verizon");
string filename = @"PingLog.csv";
{
using (var writer = new StreamWriter(filename, true))
{
foreach(string website in lstWebSites)
{
writer.WriteLine(website);
try
{
Ping myPing = new Ping();
PingReply reply = myPing.Send(website, 1000);
if (reply != null)
{
Console.WriteLine("{0}, {1}", reply.Address, reply.RoundtripTime);
}
}
catch
{
Console.WriteLine.("ERROR: You have some TIMEOUT issue");
}
}
}
}
}
}
}
输出是什么? – horns
什么是错误? –
上述代码中存在语法错误。你在使用IDE吗?你错过了文件名的引号,并且你使用了一个名为'stream'的变量而没有声明过它 –