diff --git a/README.md b/README.md index b1372fe..0767f4e 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,6 @@ On the sending host you'll see output like this (option 1): ![sending data](https://github.com/enclave-networks/multicast-test/raw/master/sending.png) -By default, the tool uses multicast stream IP address 239.0.1.2 with port 20480. Pull requests to enable customisation are welcome. - ![receiving data](https://github.com/enclave-networks/multicast-test/raw/master/receiving.png) See also the [Singlewire Multicast Testing Tool](https://support.singlewire.com/s/software-downloads/a17C0000008Dg7AIAS/ictestermulticastzip) discussed [here](https://salmannaqvi.com/2016/11/14/simple-multicast-testing-tool-for-windows/) by Salman Naqvi – 2 x CCIE. The Singlewire tool is perfectly adequate if you have a single network interface, but if you're working on systems with multiple network interfaces, this version should be quite useful. diff --git a/multicast-test/Program.cs b/multicast-test/Program.cs index c4e00b0..ba83c1c 100644 --- a/multicast-test/Program.cs +++ b/multicast-test/Program.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; +using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; using System.Text; -using System.Threading; namespace multicast_test { @@ -13,8 +9,8 @@ public class Program { public static void Main(string[] args) { - Console.WriteLine("Westgate Cyber Security - Simple Multicast Testing Tool"); - Console.WriteLine("=======================================================\n"); + Console.WriteLine("enclave.io - Simple Multicast Testing Tool"); + Console.WriteLine("==========================================\n"); Console.WriteLine("Interface list:\n"); Console.WriteLine($" 0: {"0.0.0.0",-40} Any"); @@ -53,6 +49,47 @@ public static void Main(string[] args) } } + // prompt to select a multicast address + Console.WriteLine(); + while (true) + { + Console.Write($"Enter multicast address (224.0.0.0 to 239.255.255.255) to use [default: {MulticastAddress}]: "); + string enteredMc = Console.ReadLine(); + if(enteredMc == null || enteredMc == string.Empty) break; // Use default multicast address + if(IPAddress.TryParse(enteredMc, out IPAddress multicastAddress)) + { + if(IsMulticast(multicastAddress)) + { + MulticastAddress = multicastAddress; + break; + } + Console.WriteLine("A multicast IP addresses must be between 224.0.0.0 to 239.255.255.255."); + continue; + } + Console.WriteLine("Not a valid IP address"); + } + + // prompt to select a multicast port + Console.WriteLine(); + while (true) + { + Console.Write($"Enter multicast port to use (between 1 and 65535) [default: {MulticastPort}]: "); + string enteredPortString = Console.ReadLine(); + if(string.IsNullOrEmpty(enteredPortString)) break; // Use default port + if(!int.TryParse(enteredPortString, out int enteredPort)) + { + Console.WriteLine("Not a valid number"); + continue; + } + if(enteredPort < 0 || enteredPort > 65535) + { + Console.WriteLine("Port must be between 1 and 65535"); + continue; + } + MulticastPort = enteredPort; + break; + } + // reset selection variable selection = -1; @@ -130,7 +167,7 @@ public static void Listen() var receiveThread = new Thread(Receive); receiveThread.Start(); - Console.WriteLine($"\nBound udp listener on {_bindingAddress}. Joined multicast group {MulticastAddress}. Waiting to receive data...\n"); + Console.WriteLine($"\nBound udp listener on {_bindingAddress}. Joined multicast group {MulticastAddress}. Port {MulticastPort}. Waiting to receive data...\n"); } public static void Receive() @@ -155,11 +192,17 @@ public static void SendMessage(UdpClient client, string message) client.Send(data, data.Length, ipEndPoint); } + private static bool IsMulticast(IPAddress ipAddress) + { + byte addressFirstOctet = ipAddress.GetAddressBytes()[0]; + return addressFirstOctet >= 224 && addressFirstOctet <= 239; + } + private static IPAddress _bindingAddress; - private static readonly IPAddress MulticastAddress = IPAddress.Parse("239.0.1.2"); + private static IPAddress MulticastAddress = IPAddress.Parse("239.0.1.2"); - private const int MulticastPort = 20480; + private static int MulticastPort = 20480; private static readonly Dictionary AddressDictionary = new Dictionary(); diff --git a/multicast-test/Properties/AssemblyInfo.cs b/multicast-test/Properties/AssemblyInfo.cs deleted file mode 100644 index c06f43f..0000000 --- a/multicast-test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("multicast-test")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Westgate Cyber Security")] -[assembly: AssemblyProduct("multicast-test")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2fd990db-29fa-42fe-872a-76b5bc6f2132")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/multicast-test/multicast-test.csproj b/multicast-test/multicast-test.csproj index 7597d8c..2de3857 100644 --- a/multicast-test/multicast-test.csproj +++ b/multicast-test/multicast-test.csproj @@ -1,47 +1,11 @@ - - - + + - Debug - AnyCPU - {2FD990DB-29FA-42FE-872A-76B5BC6F2132} Exe + net8.0 multicast_test - multicast-test - v4.5 - 512 + enable + disable - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - favicon-circle.ico - - - - - - - - - - - - - \ No newline at end of file + +