gpt4 book ai didi

c# - 发送电子邮件通知如果在数组中找到某个值(IP 地址)

转载 作者:太空宇宙 更新时间:2023-11-03 12:41:45 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com