Skip to content

Commit f13eb01

Browse files
Merge pull request #7 from groupmsl/master
Change multicast address and port
2 parents caf4fe1 + e27b44f commit f13eb01

File tree

4 files changed

+60
-90
lines changed

4 files changed

+60
-90
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ On the sending host you'll see output like this (option 1):
1616

1717
![sending data](https://github.com/enclave-networks/multicast-test/raw/master/sending.png)
1818

19-
By default, the tool uses multicast stream IP address 239.0.1.2 with port 20480. Pull requests to enable customisation are welcome.
20-
2119
![receiving data](https://github.com/enclave-networks/multicast-test/raw/master/receiving.png)
2220

2321
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.

multicast-test/Program.cs

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Net;
1+
using System.Net;
52
using System.Net.NetworkInformation;
63
using System.Net.Sockets;
74
using System.Text;
8-
using System.Threading;
95

106
namespace multicast_test
117
{
128
public class Program
139
{
1410
public static void Main(string[] args)
1511
{
16-
Console.WriteLine("Westgate Cyber Security - Simple Multicast Testing Tool");
17-
Console.WriteLine("=======================================================\n");
12+
Console.WriteLine("enclave.io - Simple Multicast Testing Tool");
13+
Console.WriteLine("==========================================\n");
1814
Console.WriteLine("Interface list:\n");
1915
Console.WriteLine($" 0: {"0.0.0.0",-40} Any");
2016

@@ -53,6 +49,47 @@ public static void Main(string[] args)
5349
}
5450
}
5551

52+
// prompt to select a multicast address
53+
Console.WriteLine();
54+
while (true)
55+
{
56+
Console.Write($"Enter multicast address (224.0.0.0 to 239.255.255.255) to use [default: {MulticastAddress}]: ");
57+
string enteredMc = Console.ReadLine();
58+
if(enteredMc == null || enteredMc == string.Empty) break; // Use default multicast address
59+
if(IPAddress.TryParse(enteredMc, out IPAddress multicastAddress))
60+
{
61+
if(IsMulticast(multicastAddress))
62+
{
63+
MulticastAddress = multicastAddress;
64+
break;
65+
}
66+
Console.WriteLine("A multicast IP addresses must be between 224.0.0.0 to 239.255.255.255.");
67+
continue;
68+
}
69+
Console.WriteLine("Not a valid IP address");
70+
}
71+
72+
// prompt to select a multicast port
73+
Console.WriteLine();
74+
while (true)
75+
{
76+
Console.Write($"Enter multicast port to use (between 1 and 65535) [default: {MulticastPort}]: ");
77+
string enteredPortString = Console.ReadLine();
78+
if(string.IsNullOrEmpty(enteredPortString)) break; // Use default port
79+
if(!int.TryParse(enteredPortString, out int enteredPort))
80+
{
81+
Console.WriteLine("Not a valid number");
82+
continue;
83+
}
84+
if(enteredPort < 0 || enteredPort > 65535)
85+
{
86+
Console.WriteLine("Port must be between 1 and 65535");
87+
continue;
88+
}
89+
MulticastPort = enteredPort;
90+
break;
91+
}
92+
5693
// reset selection variable
5794
selection = -1;
5895

@@ -130,7 +167,7 @@ public static void Listen()
130167
var receiveThread = new Thread(Receive);
131168
receiveThread.Start();
132169

133-
Console.WriteLine($"\nBound udp listener on {_bindingAddress}. Joined multicast group {MulticastAddress}. Waiting to receive data...\n");
170+
Console.WriteLine($"\nBound udp listener on {_bindingAddress}. Joined multicast group {MulticastAddress}. Port {MulticastPort}. Waiting to receive data...\n");
134171
}
135172

136173
public static void Receive()
@@ -155,11 +192,17 @@ public static void SendMessage(UdpClient client, string message)
155192
client.Send(data, data.Length, ipEndPoint);
156193
}
157194

195+
private static bool IsMulticast(IPAddress ipAddress)
196+
{
197+
byte addressFirstOctet = ipAddress.GetAddressBytes()[0];
198+
return addressFirstOctet >= 224 && addressFirstOctet <= 239;
199+
}
200+
158201
private static IPAddress _bindingAddress;
159202

160-
private static readonly IPAddress MulticastAddress = IPAddress.Parse("239.0.1.2");
203+
private static IPAddress MulticastAddress = IPAddress.Parse("239.0.1.2");
161204

162-
private const int MulticastPort = 20480;
205+
private static int MulticastPort = 20480;
163206

164207
private static readonly Dictionary<int, IPAddress> AddressDictionary = new Dictionary<int, IPAddress>();
165208

multicast-test/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

multicast-test/multicast-test.csproj

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{2FD990DB-29FA-42FE-872A-76B5BC6F2132}</ProjectGuid>
84
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
96
<RootNamespace>multicast_test</RootNamespace>
10-
<AssemblyName>multicast-test</AssemblyName>
11-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12-
<FileAlignment>512</FileAlignment>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>disable</Nullable>
139
</PropertyGroup>
14-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15-
<PlatformTarget>AnyCPU</PlatformTarget>
16-
<DebugSymbols>true</DebugSymbols>
17-
<DebugType>full</DebugType>
18-
<Optimize>false</Optimize>
19-
<OutputPath>bin\Debug\</OutputPath>
20-
<DefineConstants>DEBUG;TRACE</DefineConstants>
21-
<ErrorReport>prompt</ErrorReport>
22-
<WarningLevel>4</WarningLevel>
23-
</PropertyGroup>
24-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25-
<PlatformTarget>AnyCPU</PlatformTarget>
26-
<DebugType>pdbonly</DebugType>
27-
<Optimize>true</Optimize>
28-
<OutputPath>bin\Release\</OutputPath>
29-
<DefineConstants>TRACE</DefineConstants>
30-
<ErrorReport>prompt</ErrorReport>
31-
<WarningLevel>4</WarningLevel>
32-
</PropertyGroup>
33-
<PropertyGroup>
34-
<ApplicationIcon>favicon-circle.ico</ApplicationIcon>
35-
</PropertyGroup>
36-
<ItemGroup>
37-
<Reference Include="System" />
38-
</ItemGroup>
39-
<ItemGroup>
40-
<Compile Include="Program.cs" />
41-
<Compile Include="Properties\AssemblyInfo.cs" />
42-
</ItemGroup>
43-
<ItemGroup>
44-
<Content Include="favicon-circle.ico" />
45-
</ItemGroup>
46-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
47-
</Project>
10+
11+
</Project>

0 commit comments

Comments
 (0)