From c1d783b1e7476fba7368f59f1b1b9ce7519fc105 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Fri, 12 Jul 2024 14:06:45 -0400 Subject: [PATCH] Use DnsClient.Net library to get nk cloud IP --- nksrv/Utils/AssetDownloadUtil.cs | 23 ++++++++++++++++++++--- nksrv/nksrv.csproj | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/nksrv/Utils/AssetDownloadUtil.cs b/nksrv/Utils/AssetDownloadUtil.cs index 38729f9..5dbb78c 100644 --- a/nksrv/Utils/AssetDownloadUtil.cs +++ b/nksrv/Utils/AssetDownloadUtil.cs @@ -1,4 +1,5 @@ -using Swan.Logging; +using DnsClient; +using Swan.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -11,6 +12,8 @@ namespace nksrv.Utils public class AssetDownloadUtil { public static readonly HttpClient AssetDownloader = new(new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.All }); + + private static string? CloudIp = null; public static async Task DownloadOrGetFileAsync(string url, CancellationToken cancellationToken) { var rawUrl = url.Replace("https://cloud.nikke-kr.com/", ""); @@ -27,9 +30,12 @@ namespace nksrv.Utils { Logger.Info("Download " + targetFile); + if (CloudIp == null) + { + CloudIp = await GetCloudIpAsync(); + } - - var requestUri = new Uri("https://35.190.17.65/" + rawUrl); + var requestUri = new Uri("https://" + CloudIp + "/" + rawUrl); using var request = new HttpRequestMessage(HttpMethod.Get, requestUri); request.Headers.TryAddWithoutValidation("host", "cloud.nikke-kr.com"); using var response = await AssetDownloader.SendAsync(request); @@ -52,5 +58,16 @@ namespace nksrv.Utils return targetFile; } + + private static async Task GetCloudIpAsync() + { + var lookup = new LookupClient(); + var result = await lookup.QueryAsync("cloud.nikke-kr.com", QueryType.A); + + var record = result.Answers.ARecords().FirstOrDefault(); + var ip = record?.Address; + + return ip.ToString(); + } } } diff --git a/nksrv/nksrv.csproj b/nksrv/nksrv.csproj index f28ed37..adc67a5 100644 --- a/nksrv/nksrv.csproj +++ b/nksrv/nksrv.csproj @@ -13,6 +13,7 @@ +