コード例 #1
0
        private string PlaySite(string arguments, FakeIP fakeip, FakeUA fakeua, bool readReponse)
        {
            // fake ip
            if (fakeip != null)
            {
                string ip;
                if (fakeip.FakeMethod == FakeIP.Method.Pick)
                {
                    ip = IPManager.GetRandom()?.IP;
                }
                else
                {
                    ip = IPManager.GetGenerate();
                }

                if (string.IsNullOrWhiteSpace(ip))
                {
                    throw new Exception(sr_fake_ip_error);
                }
                else
                {
                    arguments = arguments.Replace(fakeip.Replace, ip);
                }
            }

            // fake ua
            if (fakeua != null)
            {
                string ua = UAManager.GetRandom()?.Value;
                if (string.IsNullOrWhiteSpace(ua))
                {
                    throw new Exception(sr_fake_ua_error);
                }
                else
                {
                    arguments = arguments.Replace(fakeua.Replace, ua);
                }
            }

            // curl process
            Process process = new Process()
            {
                StartInfo =
                {
                    FileName               = Utility.CurlManager.PathCurlExe,
                    Arguments              = arguments,
                    WorkingDirectory       = App.PathCurl,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = readReponse,
                },
            };

            string response;

            try
            {
                process.Start();

                response = process.StartInfo.RedirectStandardOutput ?
                           process.StandardOutput.ReadToEnd() :
                           $"{sr_complete} {DateTime.Now.ToString("yyyy.MM.dd-HH:mm:ss")}";
                process.WaitForExit();
            }
            catch
            {
                response = $"{sr_failed} {DateTime.Now.ToString("yyyy.MM.dd-HH:mm:ss")}";
            }
            finally
            {
                process.Dispose();
            }

            return(response);
        }