Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
?
Browse files Browse the repository at this point in the history
  • Loading branch information
Yushu2606 committed Jan 24, 2024
1 parent 7d92ea1 commit c763ca4
Showing 1 changed file with 73 additions and 55 deletions.
128 changes: 73 additions & 55 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Hosting;
using System.Text.Encodings.Web;
using System.Text.Json;
using Tea;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Configuration.Sources.Clear();
Expand All @@ -29,77 +30,94 @@
});
while (true)
{
using HttpClient httpClient = new();
string? ipv4 = default;
string? ipv6 = default;
try
{
string response = await httpClient.GetStringAsync("https://ipv4.test-ipv6.com/ip/");
string dataString = Regex.DataRegex().Match(response).Groups[1].Value;
Data? data = JsonSerializer.Deserialize<Data>(dataString);
ipv4 = data!.Ip;
}
catch (Exception ex) when (ex is NullReferenceException or HttpRequestException)
{
}
using HttpClient httpClient = new();
string? ipv4 = default;
string? ipv6 = default;
try
{
string response = await httpClient.GetStringAsync("https://ipv4.test-ipv6.com/ip/");
string dataString = Regex.DataRegex().Match(response).Groups[1].Value;
Data? data = JsonSerializer.Deserialize<Data>(dataString);
ipv4 = data!.Ip;
}
catch (Exception ex) when (ex is NullReferenceException or HttpRequestException)
{
}

try
{
string response = await httpClient.GetStringAsync("https://ipv6.test-ipv6.com/ip/");
string dataString = Regex.DataRegex().Match(response).Groups[1].Value;
Data? data = JsonSerializer.Deserialize<Data>(dataString);
ipv6 = data!.Ip;
}
catch (Exception ex) when (ex is NullReferenceException or HttpRequestException)
{
}
try
{
string response = await httpClient.GetStringAsync("https://ipv6.test-ipv6.com/ip/");
string dataString = Regex.DataRegex().Match(response).Groups[1].Value;
Data? data = JsonSerializer.Deserialize<Data>(dataString);
ipv6 = data!.Ip;
}
catch (Exception ex) when (ex is NullReferenceException or HttpRequestException)
{
}

foreach (Domain domain in config.Domains)
{
foreach (string subDomain in domain.SubDomains)
foreach (Domain domain in config.Domains)
{
DescribeDomainRecordsRequest request = new()
{
DomainName = domain.Name,
RRKeyWord = subDomain
};
DescribeDomainRecordsResponse response = await client.DescribeDomainRecordsAsync(request);
foreach (DescribeDomainRecordsResponseBody.DescribeDomainRecordsResponseBodyDomainRecords.
DescribeDomainRecordsResponseBodyDomainRecordsRecord record in response.Body.DomainRecords
.Record)
foreach (string subDomain in domain.SubDomains)
{
UpdateDomainRecordRequest updateRequest = new()
DescribeDomainRecordsRequest request = new()
{
RecordId = record.RecordId,
RR = record.RR,
Type = record.Type
DomainName = domain.Name,
RRKeyWord = subDomain
};
switch (record.Type)
DescribeDomainRecordsResponse response = await client.DescribeDomainRecordsAsync(request);
foreach (DescribeDomainRecordsResponseBody.DescribeDomainRecordsResponseBodyDomainRecords.
DescribeDomainRecordsResponseBodyDomainRecordsRecord record in response.Body.DomainRecords
.Record)
{
case "A":
if (!string.IsNullOrWhiteSpace(ipv4) || record.Value == ipv4)
{
continue;
}
UpdateDomainRecordRequest updateRequest = new()
{
Line = record.Line,
Priority = record.Priority,
RR = record.RR,
RecordId = record.RecordId,
TTL = record.TTL,
Type = record.Type
};
switch (record.Type)
{
case "A":
if (!string.IsNullOrWhiteSpace(ipv4) || record.Value == ipv4)
{
continue;
}

updateRequest.Value = ipv4;
break;
case "AAAA":
if (!string.IsNullOrWhiteSpace(ipv6) || record.Value == ipv6)
{
continue;
}

updateRequest.Value = ipv4;
break;
case "AAAA":
if (!string.IsNullOrWhiteSpace(ipv6) || record.Value == ipv6)
{
updateRequest.Value = ipv6;
break;
default:
continue;
}
}

updateRequest.Value = ipv6;
break;
default:
continue;
try
{
await client.UpdateDomainRecordAsync(updateRequest);
}
catch (TeaException)
{
}
}

await client.UpdateDomainRecordAsync(updateRequest);
}
}
}
catch (Exception ex)
{
Directory.CreateDirectory("logs");
File.AppendAllText($"logs/{DateTime.Now:yy-MM-ddTHH-mm-ss}", ex.ToString());
}

await Task.Delay(config.Interval);
}

0 comments on commit c763ca4

Please sign in to comment.