Skip to content

Commit

Permalink
Merge pull request #7 from groupmsl/master
Browse files Browse the repository at this point in the history
Change multicast address and port
  • Loading branch information
enclave-marc-barry authored Jan 5, 2024
2 parents caf4fe1 + e27b44f commit f13eb01
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 90 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
63 changes: 53 additions & 10 deletions multicast-test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
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
{
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");

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand All @@ -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<int, IPAddress> AddressDictionary = new Dictionary<int, IPAddress>();

Expand Down
35 changes: 0 additions & 35 deletions multicast-test/Properties/AssemblyInfo.cs

This file was deleted.

50 changes: 7 additions & 43 deletions multicast-test/multicast-test.csproj
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2FD990DB-29FA-42FE-872A-76B5BC6F2132}</ProjectGuid>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>multicast_test</RootNamespace>
<AssemblyName>multicast-test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>favicon-circle.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon-circle.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

</Project>

0 comments on commit f13eb01

Please sign in to comment.