public int Send(string sourceIp, string targetIp, int udpPort, TimeSpan delay, TimeSpan duration, List<string> source)
 {
     var start = DateTime.UtcNow;
     var localCounter = 0;
     using (var UC = new UdpClient(new IPEndPoint(IPAddress.Parse(sourceIp), 0)))
     {
         while (DateTime.UtcNow < start.Add(duration))
         {
             var txtMsg = source[localCounter % source.Count];
             var msg = Encoding.ASCII.GetBytes(txtMsg);
             var defMatch = SyslogParser.DefaultParser.Match(txtMsg);
             var privalMatch = defMatch.Groups["PRIVAL"].Value.Trim();
             var prival = int.Parse(privalMatch);
             var sent = new SimpleTxSyslog()
             {
                 Sev = (Severity)Enum.ToObject(typeof(Severity), prival & 0x7),
                 Fac = (Facility)Enum.ToObject(typeof(Facility), prival >> 3),
                 Message = defMatch.Groups["MESSAGE"].Value.Trim(),
             };
             this.SentList.Add(sent);
             UC.Send(msg, msg.Length, targetIp, udpPort);
             localCounter++;
             Thread.Sleep(delay);
         }
     }
     return localCounter;
 }
Exemple #2
0
        public int Send(string sourceIp, string targetIp, int udpPort, TimeSpan delay, TimeSpan duration, List <string> source)
        {
            var start        = DateTime.UtcNow;
            var localCounter = 0;

            using (var UC = new UdpClient(new IPEndPoint(IPAddress.Parse(sourceIp), 0)))
            {
                while (DateTime.UtcNow < start.Add(duration))
                {
                    var txtMsg      = source[localCounter % source.Count];
                    var msg         = Encoding.ASCII.GetBytes(txtMsg);
                    var defMatch    = SyslogParser.DefaultParser.Match(txtMsg);
                    var privalMatch = defMatch.Groups["PRIVAL"].Value.Trim();
                    var prival      = int.Parse(privalMatch);
                    var sent        = new SimpleTxSyslog()
                    {
                        Sev     = (Severity)Enum.ToObject(typeof(Severity), prival & 0x7),
                        Fac     = (Facility)Enum.ToObject(typeof(Facility), prival >> 3),
                        Message = defMatch.Groups["MESSAGE"].Value.Trim(),
                    };
                    this.SentList.Add(sent);
                    UC.Send(msg, msg.Length, targetIp, udpPort);
                    localCounter++;
                    Thread.Sleep(delay);
                }
            }
            return(localCounter);
        }