Esempio n. 1
0
        private void exhausitiverThread(Object obj)
        {
            Dictionary <String, String> currentParam = dicHandle.nextParam();

            while (currentParam != null && currentParam.Count > 0 && running && dicHandle.totalNums >= currentPersion)
            {
                try
                {
                    Int32  length           = commConfig.General.Body.Length;
                    string postBody         = commConfig.General.Body;
                    string currentParamJson = JsonHandle.toJson(currentParam);
                    foreach (string paraName in currentParam.Keys)
                    {
                        postBody = postBody.Replace("${" + paraName + "}", currentParam[paraName]);
                    }
                    ExhausitiverEntity threadExhausitiverEntity = ExhausitiverEntity.parseExhausitiver(commConfig.General.Protocol, commConfig.General.Encode, commConfig.General.TimeOut, postBody);
                    ExhaustiverResult  result = ExhausitiverHandle.doExhausitiver(threadExhausitiverEntity, commConfig.Verification);
                    result.Param = currentParam;
                    if (result.Success == true)
                    {
                        if (SuccessStopCheckBox.Checked)
                        {
                            running = false;
                        }
                        ExhaustiverResultTextBox.AppendText(currentParamJson + "\r\n");
                    }
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = "0";
                    lvi.SubItems.Add(currentParamJson);
                    lvi.SubItems.Add(Convert.ToString(result.Code));
                    lvi.SubItems.Add(Convert.ToString(result.Length));
                    lvi.SubItems.Add(result.Success ? "成功" : "失败");
                    lvi.SubItems.Add(threadExhausitiverEntity.Body + "\n\n" + result.Result);
                    if (result.Success)
                    {
                        lvi.ForeColor = Color.Green;
                    }
                    paramPersion = lvi;
                    lviQueues.Enqueue(lvi);
                    if (result.Success)
                    {
                        if (SuccessStopCheckBox.Checked)
                        {
                            break;
                        }
                    }
                }
                catch { }
                finally
                {
                    speed++;
                    currentPersion++;
                    currentParam = dicHandle.nextParam();
                }
                Thread.Sleep(1);
            }
        }
Esempio n. 2
0
        private ExhausitiverConfig parseConfig()
        {
            ExhausitiverConfig config  = new ExhausitiverConfig();
            ExhausitiverEntity general = new ExhausitiverEntity();

            general.Protocol  = ConfigProtocolComboBox.Text;
            general.Host      = ConfigHostTextBox.Text.Trim();
            general.Method    = ConfigMethodComboBox.Text;
            general.Port      = Convert.ToInt32(ConfigPortTextBox.Text);
            general.TimeOut   = Convert.ToInt32(ConfigTimeOutCombox.Text.Replace("秒", "")) * 1000;
            general.Encode    = ConfigEncodeComboBox.Text;
            general.Data      = Encoding.GetEncoding(ConfigEncodeComboBox.Text.Equals("自动") ? "UTF-8" : ConfigEncodeComboBox.Text).GetBytes(ConfigBodyTextBox.Text);
            general.Body      = ConfigBodyTextBox.Text;
            general.ThreadNum = Convert.ToInt32(ConfigThreadNumComboBox.Text);
            config.General    = general;
            ExhaustiverVerification verification = new ExhaustiverVerification();

            verification.CalcType         = ConfigCalcComboBox.SelectedIndex;
            verification.VerificationType = ConfigVerificationTypeComboBox.SelectedIndex;
            verification.Value            = ConfigVerificationValueTextBox.Text;
            verification.SuccessThenStop  = (SuccessStopCheckBox.Checked)?true:false;
            config.Verification           = verification;
            List <ExhausitiverDic> dics = new List <ExhausitiverDic>();

            for (int i = 0; i < DicsListview.Items.Count; i++)
            {
                ExhausitiverDic dic = new ExhausitiverDic();
                dic.ParamName = DicsListview.Items[i].SubItems[0].Text;
                dic.Path      = DicsListview.Items[i].SubItems[1].Text;
                dics.Add(dic);
            }
            config.Dics = dics;
            String     json = JsonHandle.toJson(config);
            FileStream fs   = new FileStream(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".conf", FileMode.Create);

            byte[] data = System.Text.Encoding.Default.GetBytes(json);
            fs.Write(data, 0, data.Length);
            fs.Flush();
            fs.Close();
            return(config);
        }
 public static ExhaustiverResult doExhausitiver(ExhausitiverEntity general, ExhaustiverVerification verification)
 {
     try
     {
         HttpExhaustiver.handle.HttpHandle.HttpResult httpResult;
         if (general.Protocol.ToLower().Equals("http"))
         {
             httpResult = httpHandles[verification.VerificationType].httpSendData(general.Host, general.Port, general.TimeOut, general.Encode, general.Data);
         }
         else
         {
             httpResult = httpHandles[verification.VerificationType].httpsSendData(general.Host, general.Port, general.TimeOut, general.Encode, general.Data);
         }
         ExhaustiverResult result = new ExhaustiverResult();
         result.Code    = httpResult.Code;
         result.Result  = httpResult.Header + "\r\n" + httpResult.Body;
         result.Length  = result.Result.Length;
         result.UnionId = Guid.NewGuid().ToString("N");
         if (verification.VerificationType == 0)
         {
             if (httpResult.Code == -1)
             {
                 return(result);
             }
             if (httpResult.Code == Convert.ToInt32(verification.Value.Trim()))
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         String verificationBody = httpResult.Header;
         if (verification.VerificationType == 2)
         {
             if (String.IsNullOrEmpty(httpResult.Body))
             {
                 return(result);
             }
             verificationBody = httpResult.Body;
         }
         else if (verification.VerificationType == 3)
         {
             if (String.IsNullOrEmpty(httpResult.Body))
             {
                 return(result);
             }
             verificationBody = httpResult.Header + "\n" + httpResult.Body;
         }
         if (verification.CalcType == 0)
         {
             if (verificationBody.Equals(verification.Value))
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         if (verification.CalcType == 1)
         {
             if (!verificationBody.Equals(verification.Value))
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         if (verification.CalcType == 2)
         {
             if (verificationBody.Contains(verification.Value))
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         if (verification.CalcType == 3)
         {
             if (!verificationBody.Contains(verification.Value))
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         if (verification.CalcType == 4)
         {
             List <String> matchResult = matchExport(verificationBody, new Regex(verification.Value));
             if (matchResult != null && matchResult.Count > 0)
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         if (verification.CalcType == 5)
         {
             List <String> matchResult = matchExport(verificationBody, new Regex(verification.Value));
             if (matchResult != null && matchResult.Count > 0)
             {
                 result.Success = true;
                 return(result);
             }
             return(result);
         }
         return(result);
     }
     catch
     {
         return(new ExhaustiverResult());
     }
 }