From e9217359eecaaaede7b19d713051e8b0a8532b6f Mon Sep 17 00:00:00 2001 From: Andy Cornford Date: Thu, 4 Jan 2024 15:59:38 +0000 Subject: [PATCH 1/4] * Now possible to change multicast address and port * Ported to .NET 8 --- multicast-test/Program.cs | 34 ++++++++++++++- multicast-test/Properties/AssemblyInfo.cs | 35 ---------------- multicast-test/multicast-test.csproj | 50 ++++------------------- 3 files changed, 39 insertions(+), 80 deletions(-) delete mode 100644 multicast-test/Properties/AssemblyInfo.cs diff --git a/multicast-test/Program.cs b/multicast-test/Program.cs index c4e00b0..f410ede 100644 --- a/multicast-test/Program.cs +++ b/multicast-test/Program.cs @@ -53,6 +53,36 @@ public static void Main(string[] args) } } + // prompt to select a multicast address + Console.WriteLine(); + while (true) + { + Console.Write("Enter multicast address to use: "); + string? enteredMc = Console.ReadLine(); + + if(enteredMc == null || enteredMc == string.Empty) continue; + List enteredMcSplit = new List(); + enteredMc.Split(".").ToList().ForEach(x => enteredMcSplit.Add(Convert.ToInt32(x))); + if(enteredMcSplit.Count != 4) continue; // Not enough parts + if(enteredMcSplit[0] < 224 || enteredMcSplit[0] > 239) continue; // Check first part + for(int part = 1; part < 4; part++) if(enteredMcSplit[part] < 0 || enteredMcSplit[part] > 255) continue; // Check other parts + MulticastAddress = IPAddress.Parse(enteredMc); + break; + } + + // prompt to select a multicast port + Console.WriteLine(); + while (true) + { + Console.Write("Enter multicast port to use: "); + string? enteredPortString = Console.ReadLine(); + if(enteredPortString == null || enteredPortString == string.Empty) continue; + if(!int.TryParse(enteredPortString, out int enteredPort)) continue; + if(enteredPort < 0 || enteredPort > 65535) continue; + MulticastPort = enteredPort; + break; + } + // reset selection variable selection = -1; @@ -157,9 +187,9 @@ public static void SendMessage(UdpClient client, string message) 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..5394a14 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 + enable - - 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 + + From 1aad00d6a32215b4cbc0a02d8c53c81ef3822fa0 Mon Sep 17 00:00:00 2001 From: Andy Cornford Date: Thu, 4 Jan 2024 16:16:30 +0000 Subject: [PATCH 2/4] Updared readme --- README.md | 2 -- 1 file changed, 2 deletions(-) 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. From 0ac2ace75f9aafe6dfa21ca29c9456a967407eac Mon Sep 17 00:00:00 2001 From: Andy Cornford Date: Fri, 5 Jan 2024 11:41:50 +0000 Subject: [PATCH 3/4] * More efficient checking of multicast addresses * Allows default multicast address and port to be used (with empty input) * Better logging on error --- multicast-test/Program.cs | 51 ++++++++++++++++++---------- multicast-test/multicast-test.csproj | 2 +- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/multicast-test/Program.cs b/multicast-test/Program.cs index f410ede..592932e 100644 --- a/multicast-test/Program.cs +++ b/multicast-test/Program.cs @@ -57,28 +57,39 @@ public static void Main(string[] args) Console.WriteLine(); while (true) { - Console.Write("Enter multicast address to use: "); - string? enteredMc = Console.ReadLine(); - - if(enteredMc == null || enteredMc == string.Empty) continue; - List enteredMcSplit = new List(); - enteredMc.Split(".").ToList().ForEach(x => enteredMcSplit.Add(Convert.ToInt32(x))); - if(enteredMcSplit.Count != 4) continue; // Not enough parts - if(enteredMcSplit[0] < 224 || enteredMcSplit[0] > 239) continue; // Check first part - for(int part = 1; part < 4; part++) if(enteredMcSplit[part] < 0 || enteredMcSplit[part] > 255) continue; // Check other parts - MulticastAddress = IPAddress.Parse(enteredMc); - break; + Console.Write($"Enter multicast address to use [{MulticastAddress}]: "); + string enteredMc = Console.ReadLine(); + if(enteredMc == null || enteredMc == string.Empty) break; // Use defult 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: "); - string? enteredPortString = Console.ReadLine(); - if(enteredPortString == null || enteredPortString == string.Empty) continue; - if(!int.TryParse(enteredPortString, out int enteredPort)) continue; - if(enteredPort < 0 || enteredPort > 65535) continue; + Console.Write($"Enter multicast port to use [{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; } @@ -160,7 +171,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() @@ -185,6 +196,12 @@ 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 IPAddress MulticastAddress = IPAddress.Parse("239.0.1.2"); diff --git a/multicast-test/multicast-test.csproj b/multicast-test/multicast-test.csproj index 5394a14..2de3857 100644 --- a/multicast-test/multicast-test.csproj +++ b/multicast-test/multicast-test.csproj @@ -5,7 +5,7 @@ net8.0 multicast_test enable - enable + disable From e27b44fa11101565fc6ca9d7c6fda0589894c412 Mon Sep 17 00:00:00 2001 From: Marc Barry <67782240+enclave-marc-barry@users.noreply.github.com> Date: Fri, 5 Jan 2024 17:39:18 +0000 Subject: [PATCH 4/4] minor adjustments - remove extra using statements - update tool name - fix spelling mistake in a comment - clarify the range of expected inputs --- multicast-test/Program.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/multicast-test/Program.cs b/multicast-test/Program.cs index 592932e..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"); @@ -57,9 +53,9 @@ public static void Main(string[] args) Console.WriteLine(); while (true) { - Console.Write($"Enter multicast address to use [{MulticastAddress}]: "); + 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 defult multicast address + if(enteredMc == null || enteredMc == string.Empty) break; // Use default multicast address if(IPAddress.TryParse(enteredMc, out IPAddress multicastAddress)) { if(IsMulticast(multicastAddress)) @@ -77,7 +73,7 @@ public static void Main(string[] args) Console.WriteLine(); while (true) { - Console.Write($"Enter multicast port to use [{MulticastPort}]: "); + 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))