示例#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);
            }
        }
 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());
     }
 }