-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
100 lines (90 loc) · 3 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
namespace AliDDNS
{
public class Program
{
public static void Main(string[] args)
{
string help_str = "Usage: ddns <list | update> -id <AccessKey ID> -key <AccessKey> -domain <domain> [-subdomain <subdomain>] [-record_id <record_id>]";
int argc = args.Length;
if (argc < 7)
{
Console.WriteLine(help_str);
return;
}
string id = string.Empty;
string secret = string.Empty;
string domain = string.Empty;
string subDomain = string.Empty;
string? recordId = null;
string command = args[0];
if (command != "list" && command != "update")
{
Console.WriteLine(help_str);
return;
}
try
{
for (int i = 1; i < argc; i++)
{
switch (args[i])
{
case "-id":
id = args[++i];
break;
case "-key":
secret = args[++i];
break;
case "-domain":
domain = args[++i];
break;
case "-subdomain":
subDomain = args[++i].ToLower();
break;
case "-record_id":
recordId = args[++i];
break;
default:
break;
}
}
}
catch
{
Console.WriteLine(help_str);
return;
}
if (!string.IsNullOrEmpty(subDomain) && !string.IsNullOrEmpty(recordId))
{
Console.WriteLine("[WARN] Subdomain would be ignored if record_id is specified.");
}
AccessKey accessKey = new(id, secret);
ServiceConfiguration config = new(domain, accessKey, subDomain, recordId);
var ddns = new AliyunDDNSUpdater(config);
if (command == "list")
{
ListRecords(ddns);
}
else if (command == "update")
{
UpdateDNS(ddns);
}
}
private static void ListRecords(AliyunDDNSUpdater ddns)
{
string records = ddns.ListRecords();
Console.WriteLine(records);
}
private static void UpdateDNS(AliyunDDNSUpdater ddns)
{
bool result = ddns.UpdateDNS();
if (result)
{
Console.WriteLine("Updated.");
}
else
{
Console.WriteLine("Failed update.");
}
}
}
}