-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
52 lines (48 loc) · 1.4 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class Program
{
private static string IP;
private static int PORT;
static void Main(string[] args)
{
if (args.Length > 0)
{
if (args.Length == 2)
{
IP = args[0];
PORT = Convert.ToInt32(args[1]);
}
} else
{
Console.Write("IP: ");
IP = Console.ReadLine();
Console.Write("PORT: ");
PORT = Convert.ToInt32(Console.ReadLine());
if (IP == null)
{
Console.WriteLine("Invalid IP");
Thread.Sleep(1000);
Environment.Exit(0);
}
}
while (true)
{
Console.Write("> ");
byte[] cmd = Encoding.ASCII.GetBytes(Console.ReadLine());
try
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress ip = IPAddress.Parse(IP);
IPEndPoint endPoint = new IPEndPoint(ip, PORT);
sock.SendTo(cmd, endPoint);
Console.WriteLine("Successfully sent message.");
} catch (Exception ex)
{
Console.WriteLine("Failed to send message. Error: " + ex.Message);
}
}
}
}