public async Task CheckIpAndUpdateDDNSIfNeeded(CancellationToken cancellationToken) { using HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_cloudflareSettings.Token}"); var ip = await GetExternalIpAddress(httpClient, cancellationToken); _logger.LogDebug($"External IP found: {ip}"); var lastIp = await _persistenceService.GetLatestIp(); if (string.IsNullOrEmpty(lastIp) || !lastIp.Equals(ip.ToString())) { _logger.LogInformation("Starting update on Cloudflare"); await UpdateCloudflareDDNSIP(httpClient, ip, cancellationToken); _logger.LogInformation("Saving IP to file"); await _persistenceService.SaveNewIp(ip.ToString()); _logger.LogInformation("Update completed successfully"); } else { _logger.LogInformation($"Last IP matches new one {ip}, skipping update."); } }