-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(traffic): a program to log MDNS traffic
- Loading branch information
1 parent
e487a7e
commit d479d16
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |