我有一个C#控制台应用程序,并且希望能够在阵列中找到任何非本地IP地址时将电子邮件发送到某个地址,我假设我将使用If!=语句,但无法获取任何信息工作。任何提示或帮助将不胜感激。

    System.Net.IPAddress[] addresslist = Dns.GetHostAddresses(C);
   {
     string IPs = "";
     bool firstIP = true;
     foreach (IPAddress ip in addresslist)
         {
            if (!firstIP)
                {
                   IPs = IPs + ",";

                }
                    IPs = IPs + ip;
                    firstIP = false;
                   }
                     addresslist.ToString();
      if addresslist != { "10.1.20.99"} //example, have multiple IP's
       then //..... this is where I am stuck

最佳答案

您可以使用以下方法删除本地地址

var filteredIPs =  ipaddresslist.Where(p => !p.StartsWith("10.1"));


然后,您可以发送诸如sendimportantmails(String.Join(",", filteredIPs));之类的消息

关于c# - 发送电子邮件通知如果在阵列中找到某个值(IP地址),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38768752/

10-11 15:53