Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.IO;
- using System.Threading;
- namespace TCPClient
- {
- class TClient
- {
- static void Main(string[] args)
- {
- String IP;
- String Port;
- String Option;
- Console.Write("Please give IP: ");
- IP = Console.ReadLine();
- Console.Write("Please give Port: ");
- Port = Console.ReadLine();
- Console.WriteLine("-------------------------------");
- // Clear Console
- Console.Clear();
- Hereweare:
- Console.WriteLine("\n1) <Chat Mode> - You just send messages to server");
- Console.WriteLine("2) <Flood Mode> - You spam server with packets");
- Console.Write("\nPlease select Mode: ");
- Option = Console.ReadLine();
- Console.WriteLine("-------------------------------");
- if (Option == "1")
- CMode(IP, Convert.ToInt32(Port));
- else if (Option == "2")
- Flood(IP, Convert.ToInt32(Port));
- else
- {
- Console.WriteLine("Wrong Selection, Please use 1 or 2");
- Console.WriteLine("Console will be clear in 3 seconds");
- Thread.Sleep(3000);
- // Clear Console from old messags
- Console.Clear();
- // Go upp for repeat
- goto Hereweare;
- }
- }
- private static Socket socket;
- private static IPEndPoint Host;
- private static System.Net.Sockets.TcpClient Client;
- public static void CMode(string IP, int Port)
- {
- Console.Clear();
- // Create Socket
- socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- Host = new IPEndPoint(IPAddress.Parse(IP), Port);
- Client = new TcpClient();
- try
- {
- // TCPClient connect to server...
- Console.WriteLine("Connecting...");
- Client.Connect(IPAddress.Parse(IP), Port);
- }
- catch (Exception)
- { Console.WriteLine("Connection To " + IP + " in Port " + Port + " has failed!"); return; }
- Console.WriteLine("Write your message.");
- Console.WriteLine("---------------------------------");
- try
- {
- while (Client.Connected)
- {
- // Read Message
- String Message = Console.ReadLine();
- Stream Stre = Client.GetStream();
- // Get Time
- String Date = DateTime.Now.ToString("HH:mm:ss: ");
- ASCIIEncoding ASCII = new ASCIIEncoding();
- Byte[] Buff = ASCII.GetBytes(Date + ": " + Message);
- // Kernel - Sending packets to TARGET
- Stre.Write(Buff, 0, Buff.Length);
- }
- }
- catch (Exception)
- { Console.WriteLine("Client Disconected"); }
- //Close TCP
- Client.Close();
- }
- public static void Flood(string IP, int Port)
- {
- Console.Clear();
- // Create Socket
- socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- Host = new IPEndPoint(IPAddress.Parse(IP), Port);
- Client = new TcpClient();
- // TCPClient connect to server...
- Console.WriteLine("Connecting...");
- try
- {
- // Socket connect : Flood
- socket.Connect(Host);
- }
- catch (Exception)
- { Console.WriteLine("Socket connection to {0} at Port {1} has failed!",IP,Port); }
- Console.WriteLine("Write your message.");
- Console.WriteLine("---------------------------------");
- String Message = new String('*', 10);
- try
- {
- while (Client.Connected)
- {
- Stream Stre = Client.GetStream();
- ASCIIEncoding AEncod = new ASCIIEncoding();
- Byte[] Buff = AEncod.GetBytes(Message);
- // Kernel, send message to server.
- socket.Send(Buff);
- }
- }
- catch (Exception)
- { Console.WriteLine("Socket Disconected"); }
- // Close Socket & TCPCliet
- socket.Close();
- Client.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement