从列表中获取价值并使用它

时间:2015-08-21 09:16:10

标签: c# list socks

我正在尝试构建一个应用程序通过socks发送电子邮件,如果第一条消息是通过socks发送的,则每条消息将发送消息,第二条应该使用不同的袜子,如果我作为I Recuper,我在我的应用程序中做什么来自txt文件的信息,我添加到列表中:

try
{
    SmtpServer oServer = new SmtpServer("");

    var list = new List<string>();
    var input = File.ReadAllText(@"C:\New folder\SendMail6\socks-list.txt");
    var r = new Regex(@"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})");
    foreach (Match match in r.Matches(input))
    {
         string ip = match.Groups[1].Value;
         string port = match.Groups[2].Value;
         list.Add(ip);
         list.Add(port);
    }
    foreach (string ip in list)
    {

    }
}
catch(Exception)
{
}

我想要的是什么

oServer.SocksProxyServer = "37.187.118.174";
oServer.SocksProxyPort = 14115;

获取我通过ip值和端口完成的列表中的值,以及

如果第一封邮件是由ip发送的,则第二封邮件是使用另一个ip in list不要发送拖车邮箱,后面跟着同一个ip

由于

1 个答案:

答案 0 :(得分:0)

您需要为IP和端口

创建一个类
public class IpAndPort
{
    public string IpAddress { get; set; }
    public string Port { get; set; }
}

现在使用ConcurrentBag

using System.Collections.Concurrent;

//------
var ips =  new ConcurrentBag<IpAndPort>();
var input = File.ReadAllText(@"C:\New folder\SendMail6\socks-list.txt");
var r = new Regex(@"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})");
foreach (Match match in r.Matches(input))
{
     string ip = match.Groups[1].Value;
     string port = match.Groups[2].Value;
     if(ips.Any(x => x.IpAddress.Trim() == ip.Trim()))
         continue; 
     ips.Add(new IpAndPort { IpAddress = ip, Port = port});
}

现在通过从ConcurrentBag

获取值来发送消息
while (!ips.IsEmpty)
{
     IpAndPort ipAndPort;
     if (!ips.TryTake(out ipAndPort)) continue;
     try
     {
           //code here to send message using below IP and Port
           var ip = ipAndPort.IpAddress;
           var port = ipAndPort.Port;
           /----
           oServer = new SmtpServer("");
           oServer.SocksProxyServer = ip;
           oServer.SocksProxyPort = port;
     }
     catch (Exception ex)
     {
           Console.WriteLine(ex.Message);
     }
}
相关问题