-
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.
Merge pull request #72 from richardschneider/traffic
Multicast traffic logger
- Loading branch information
Showing
5 changed files
with
97 additions
and
6 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
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> |