Skip to content

Commit

Permalink
feat(traffic): a program to log MDNS traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jul 15, 2019
1 parent e487a7e commit d479d16
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Mdns.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spike", "Spike\Spike.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Browser", "Browser\Browser.csproj", "{A77BEF8C-440E-46F7-ACFC-5EF06EFCA4BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "traffic", "traffic\traffic.csproj", "{5E51D502-05E1-4A45-A8D6-6FB3E295D798}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -48,6 +50,10 @@ Global
{A77BEF8C-440E-46F7-ACFC-5EF06EFCA4BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A77BEF8C-440E-46F7-ACFC-5EF06EFCA4BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A77BEF8C-440E-46F7-ACFC-5EF06EFCA4BA}.Release|Any CPU.Build.0 = Release|Any CPU
{5E51D502-05E1-4A45-A8D6-6FB3E295D798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E51D502-05E1-4A45-A8D6-6FB3E295D798}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E51D502-05E1-4A45-A8D6-6FB3E295D798}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E51D502-05E1-4A45-A8D6-6FB3E295D798}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
43 changes: 43 additions & 0 deletions traffic/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Makaretu.Dns;
using System;

namespace traffic
{
class Program
{
static readonly object ttyLock = new object();

static void Main(string[] args)
{
var mdns = new MulticastService();
mdns.NetworkInterfaceDiscovered += (s, e)
=> mdns.SendQuery(ServiceDiscovery.ServiceName, type: DnsType.PTR);
mdns.AnswerReceived += OnGoodDnsMessage;
mdns.QueryReceived += OnGoodDnsMessage;
mdns.MalformedMessage += OnBadDnsMessage;
mdns.Start();
Console.ReadKey();
}

private static void OnBadDnsMessage(object sender, byte[] packet)
{
lock (ttyLock)
{
Console.WriteLine(">>> {0:O} <<<", DateTime.Now);
Console.WriteLine("Malformed message (base64)");
Console.WriteLine(Convert.ToBase64String(packet));
}

Environment.Exit(1);
}

private static void OnGoodDnsMessage(object sender, MessageEventArgs e)
{
lock (ttyLock)
{
Console.WriteLine("=== {0:O} ===", DateTime.Now);
Console.WriteLine(e.Message.ToString());
}
}
}
}
12 changes: 12 additions & 0 deletions traffic/traffic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Mdns.csproj" />
</ItemGroup>

</Project>

0 comments on commit d479d16

Please sign in to comment.