Skip to content

Commit

Permalink
Merge pull request #12 from EvotecIT/ImpproveSome
Browse files Browse the repository at this point in the history
Few improvements, fix PTR
  • Loading branch information
PrzemyslawKlys authored Nov 25, 2024
2 parents c2a25e7 + 59c1d79 commit 5b7aa38
Show file tree
Hide file tree
Showing 11 changed files with 373 additions and 350 deletions.
8 changes: 8 additions & 0 deletions DnsClientX.Examples/DemoQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public static async Task Example0() {
data.DisplayTable();
}

public static async Task ExamplePTR() {
var domains = new[] { "1.1.1.1" };
HelpersSpectre.AddLine("QueryDns", "1.1.1.1", DnsRecordType.A, "1.1.1.1");
var data = await ClientX.QueryDns(domains, DnsRecordType.PTR, "1.1.1.1", DnsRequestFormat.DnsOverHttps);
data.DisplayTable();
}



public static async Task Example1() {
HelpersSpectre.AddLine("QueryDns", "evotec.pl", DnsRecordType.A, DnsEndpoint.CloudflareWireFormat);
Expand Down
3 changes: 3 additions & 0 deletions DnsClientX.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace DnsClientX.Examples {
public static class Program {
public static async Task Main() {
await DemoQuery.ExamplePTR();
return;

// await ConvertToDnsClient.ExampleConvertToDnsClientFromX();
// await ConvertToDnsClient.ExampleConvertFromDnsClientToX();
//await DemoQuery.ExampleTesting();
Expand Down
11 changes: 5 additions & 6 deletions DnsClientX.PowerShell/DnsClientX.PowerShell.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`Windows`))' ">
netstandard2.0;net472;net6.0;net7.0;net8.0
netstandard2.0;net472;net8.0
</TargetFrameworks>
<TargetFrameworks
Condition=" '$([MSBuild]::IsOsPlatform(`OSX`))' Or '$([MSBuild]::IsOsPlatform(`Linux`))' ">
net6.0;net7.0;net8.0
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`OSX`))' Or '$([MSBuild]::IsOsPlatform(`Linux`))' ">
net8.0
</TargetFrameworks>
<Description>PowerShell Module for working with Event Logs</Description>
<AssemblyName>DnsClientX.PowerShell</AssemblyName>
<AssemblyTitle>DnsClientX.PowerShell</AssemblyTitle>
<VersionPrefix>0.3.1</VersionPrefix>
<VersionPrefix>0.3.2</VersionPrefix>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Company>Evotec</Company>
<Authors>Przemyslaw Klys</Authors>
Expand All @@ -24,7 +23,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MatejKafka.XmlDoc2CmdletDoc" Version="0.5.1">
<PackageReference Include="MatejKafka.XmlDoc2CmdletDoc" Version="0.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions DnsClientX.Tests/DnsClientX.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`Windows`))' ">
net472;net6.0;net7.0;net8.0
net472;net8.0;net9.0
</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`OSX`))' Or '$([MSBuild]::IsOsPlatform(`Linux`))' ">
net6.0;net7.0;net8.0
net8.0;net9.0
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
26 changes: 26 additions & 0 deletions DnsClientX.Tests/QueryDnsByEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,31 @@ public async void ShouldWorkForA(DnsEndpoint endpoint) {
Assert.True(answer.Data.Length > 0);
}
}

[Theory]
[InlineData(DnsEndpoint.System)]
[InlineData(DnsEndpoint.SystemTcp)]
[InlineData(DnsEndpoint.Cloudflare)]
[InlineData(DnsEndpoint.CloudflareFamily)]
[InlineData(DnsEndpoint.CloudflareSecurity)]
[InlineData(DnsEndpoint.CloudflareWireFormat)]
[InlineData(DnsEndpoint.CloudflareWireFormatPost)]
[InlineData(DnsEndpoint.Google)]
[InlineData(DnsEndpoint.GoogleWireFormat)]
[InlineData(DnsEndpoint.GoogleWireFormatPost)]
[InlineData(DnsEndpoint.Quad9)]
[InlineData(DnsEndpoint.Quad9ECS)]
[InlineData(DnsEndpoint.Quad9Unsecure)]
[InlineData(DnsEndpoint.OpenDNS)]
[InlineData(DnsEndpoint.OpenDNSFamily)]
public async void ShouldWorkForPTR(DnsEndpoint endpoint) {
var response = await ClientX.QueryDns("1.1.1.1", DnsRecordType.PTR, endpoint);
foreach (DnsAnswer answer in response.Answers) {
Assert.True(answer.Data == "one.one.one.one");
Assert.True(answer.Name == "1.1.1.1.in-addr.arpa");
Assert.True(answer.Type == DnsRecordType.PTR);
Assert.True(answer.Data.Length > 0);
}
}
}
}
14 changes: 12 additions & 2 deletions DnsClientX/Definitions/DnsAnswer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public string Name {
public string[] DataStrings => ConvertToMultiString();

/// <summary>
/// The value of the DNS record for the given name and type, escaped if necessary removing the quotes completely.
/// The value of the DNS record for the given name and type, escaped if necessary removing the quotes completely.
/// </summary>
[JsonIgnore]
public string[] DataStringsEscaped {
Expand Down Expand Up @@ -211,8 +211,18 @@ private string ConvertData() {
//Console.WriteLine($"{certificateUsage} {selector} {matchingType} {certificateAssociationData}");
return $"{certificateUsage} {selector} {matchingType} {certificateAssociationData}";

} else if (Type == DnsRecordType.PTR) {
// For PTR records, decode the domain name from the record data
try {
var output = Encoding.UTF8.GetString(Convert.FromBase64String(DataRaw));
return output.EndsWith(".") ? output.TrimEnd('.').ToLower() : output.ToLower();
} catch (FormatException) {
// If it's not Base64, return the raw data as is
return DataRaw.EndsWith(".") ? DataRaw.TrimEnd('.').ToLower() : DataRaw.ToLower();
}
} else {
return DataRaw;
// Some records return the data in a higher case (microsoft.com/NS/Quad9ECS) which needs to be fixed
return DataRaw.ToLower();
}
}
}
Expand Down
Loading

0 comments on commit 5b7aa38

Please sign in to comment.