Ejemplo n.º 1
0
        public Curl(TimelineHandler handler)
        {
            // setup
            _handler = handler;

            if (_handler.HandlerArgs.ContainsKey("stickiness"))
            {
                int.TryParse(_handler.HandlerArgs["stickiness"], out _stickiness);
            }
            if (_handler.HandlerArgs.ContainsKey("stickiness-depth-min"))
            {
                int.TryParse(_handler.HandlerArgs["stickiness-depth-min"], out _depthMin);
            }
            if (_handler.HandlerArgs.ContainsKey("stickiness-depth-max"))
            {
                int.TryParse(_handler.HandlerArgs["stickiness-depth-max"], out _depthMax);
            }

            this._currentUserAgent = UserAgentManager.Get();

            _log.Trace($"Spawning Curl with stickiness {_stickiness}/{_depthMin}/{_depthMax}...");

            // run
            try
            {
                if (_handler.Loop)
                {
                    while (true)
                    {
                        Ex();
                    }
                }
                else
                {
                    Ex();
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }
Ejemplo n.º 2
0
        private void Command(string command)
        {
            try
            {
                var escapedArgs = command;//.Replace("\"", "\\\"");

                if (!escapedArgs.Contains("--user-agent ") && !escapedArgs.Contains("-A"))
                {
                    escapedArgs += $" -A \"{UserAgentManager.Get()}\"";
                }

                Console.WriteLine($"curl {escapedArgs}");

                var p = new Process();
                p.EnableRaisingEvents              = false;
                p.StartInfo.FileName               = "curl";
                p.StartInfo.Arguments              = escapedArgs;
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.CreateNoWindow         = true;
                p.Start();

                while (!p.StandardOutput.EndOfStream)
                {
                    this.Result += p.StandardOutput.ReadToEnd();
                }

                this.Report(HandlerType.Curl.ToString(), escapedArgs, this.Result);

                Console.WriteLine(this.Result);
            }
            catch (Exception exc)
            {
                _log.Debug(exc);
            }
        }