我的代码工作正常,但是它将结果保存到.csv文件的位置我需要在其中进行一些更改。 我的结果是:在由逗号分隔的字符串行中打印所有4个乒乓
www.yahoo.com , 98.139.183.24 , 137
www.att.com , 23.72.249.145 , 20
www.yahoo.com , 98.139.183.24 , 120
www.att.com , 23.72.249.145 , 16
,我想我的结果是:
www.yahoo.com , 137 , 120
www.att.com , 20 , 16
在这个例子中,我分享只有两种结果,实际上,我回国4个结果,我需要把它们全部在一行中,我也需要摆脱IP地址。请帮帮我。然后
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
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.com");
string filename = @"PingLog.csv";
{
using (var writer = new StreamWriter(filename, true))
{
for (int i = 0; i < 4; i++)
foreach(string website in lstWebSites)
{
//writer.WriteLine(website, lstWebSites);
try
{
Ping myPing = new Ping();
PingReply reply = myPing.Send(website, 1000);
if (reply != null)
{
writer.WriteLine(website + " , " + reply.Address.ToString() + " , " + reply.RoundtripTime);
}
}
catch
{
Console.WriteLine("ERROR: You have some TIMEOUT issue");
}
}
}
}
}
}
}
更好地使用字典>() –
Steve
我不明白你的意思吗? – NewDev