Skip to content

Commit

Permalink
Merge pull request #13 from EvotecIT/FixPTRMore
Browse files Browse the repository at this point in the history
Fix ptr & bump version
  • Loading branch information
PrzemyslawKlys authored Nov 25, 2024
2 parents 5b7aa38 + 945ea8a commit 5cdd973
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DnsClientX.PowerShell/DnsClientX.PowerShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>PowerShell Module for working with Event Logs</Description>
<AssemblyName>DnsClientX.PowerShell</AssemblyName>
<AssemblyTitle>DnsClientX.PowerShell</AssemblyTitle>
<VersionPrefix>0.3.2</VersionPrefix>
<VersionPrefix>0.3.3</VersionPrefix>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Company>Evotec</Company>
<Authors>Przemyslaw Klys</Authors>
Expand Down
1 change: 0 additions & 1 deletion DnsClientX.Tests/DnsClientX.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.4.0" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
<PackageReference Include="SemanticComparison" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
Expand Down
27 changes: 24 additions & 3 deletions DnsClientX/Definitions/DnsAnswer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,37 @@ private string ConvertData() {
} else if (Type == DnsRecordType.PTR) {
// For PTR records, decode the domain name from the record data
try {
// First try to decode as Base64
var output = Encoding.UTF8.GetString(Convert.FromBase64String(DataRaw));
return output.EndsWith(".") ? output.TrimEnd('.').ToLower() : output.ToLower();
return ConvertSpecialFormatToDotted(output);
} catch (FormatException) {
// If it's not Base64, return the raw data as is
return DataRaw.EndsWith(".") ? DataRaw.TrimEnd('.').ToLower() : DataRaw.ToLower();
// If it's not Base64, try to handle it as a special format directly
return ConvertSpecialFormatToDotted(DataRaw);
}
} else {
// Some records return the data in a higher case (microsoft.com/NS/Quad9ECS) which needs to be fixed
return DataRaw.ToLower();
}
}

/// <summary>
/// Converts a special format like "\u0003one\u0003one\u0003one\u0003one\0" to a standard dotted format.
/// </summary>
/// <param name="data">The raw data in special format.</param>
/// <returns>The data in standard dotted format.</returns>
private string ConvertSpecialFormatToDotted(string data) {
if (string.IsNullOrWhiteSpace(data)) return data;

// Replace all variants of length-3 markers with dots
var result = data.Replace("\\u0003", ".")
.Replace("\\003", ".")
.Replace("\u0003", ".")
.Replace("\0", ""); // Remove null terminators

// Clean up: remove leading/trailing dots and normalize multiple dots
return Regex.Replace(result, "\\.{2,}", ".") // Replace multiple dots with single dot
.Trim('.') // Remove leading/trailing dots
.ToLower(); // Normalize case
}
}
}
6 changes: 3 additions & 3 deletions DnsClientX/DnsClientX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</Description>
<AssemblyName>DnsClientX</AssemblyName>
<AssemblyTitle>DnsClientX</AssemblyTitle>
<VersionPrefix>0.3.2</VersionPrefix>
<AssemblyVersion>0.3.2</AssemblyVersion>
<FileVersion>0.3.2</FileVersion>
<VersionPrefix>0.3.3</VersionPrefix>
<AssemblyVersion>0.3.3</AssemblyVersion>
<FileVersion>0.3.3</FileVersion>
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`Windows`))' ">
netstandard2.0;net472;net8.0;net9.0
</TargetFrameworks>
Expand Down
4 changes: 2 additions & 2 deletions Module/Build/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ Build-Module -ModuleName 'DnsClientX' {
NETProjectName = 'DnsClientX.PowerShell'
NETBinaryModule = 'DnsClientX.PowerShell.dll'
NETConfiguration = 'Release'
NETFramework = 'net472', 'net6.0'
NETFramework = 'net472', 'net8.0'
DotSourceLibraries = $true
NETSearchClass = 'DnsClientX.PowerShell.CmdletResolveDnsQuery'
}

New-ConfigurationBuild @newConfigurationBuildSplat

New-ConfigurationArtefact -Type Unpacked -Enable -Path "$PSScriptRoot\..\Artefacts\Unpacked" -RequiredModulesPath "$PSScriptRoot\..\Artefacts\Unpacked\Modules"
New-ConfigurationArtefact -Type Packed -Enable -Path "$PSScriptRoot\..\Artefacts\Packed" -IncludeTagName
New-ConfigurationArtefact -Type Packed -Enable -Path "$PSScriptRoot\..\Artefacts\Packed" -IncludeTagName -ArtefactName "DnsClientX-PowerShellModule.<TagModuleVersionWithPreRelease>.zip" -ID 'ToGitHub'

# global options for publishing to github/psgallery
#New-ConfigurationPublish -Type PowerShellGallery -FilePath 'C:\Support\Important\PowerShellGalleryAPI.txt' -Enabled:$true
Expand Down
2 changes: 1 addition & 1 deletion Module/DnsClientX.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Description = 'DnsClientX is PowerShell module that allows you to query DNS servers for information. It supports DNS over UDP, TCP and DNS over HTTPS (DoH) and DNS over TLS (DoT). It supports multiple types of DNS queries and can be used to query public DNS servers, private DNS servers and has built-in DNS Providers.'
FunctionsToExport = @()
GUID = '77fa806c-70b7-48d9-8b88-942ed73f24ed'
ModuleVersion = '0.3.1'
ModuleVersion = '0.3.2'
PowerShellVersion = '5.1'
PrivateData = @{
PSData = @{
Expand Down

0 comments on commit 5cdd973

Please sign in to comment.