Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("DnsPod Cli Tools v1.1");

            var builder = new ConfigurationBuilder();

            builder.AddCommandLine(args, new Dictionary <string, string> {
                { "-t", "Token" },
                { "-d", "DomainName" },
                { "-r", "RecordId" },
                { "-v", "Value" },
                { "-s", "SubDomain" },
                { "--type", "RecordType" }
            });
            var item = builder.Build().Get <CommandLineArgs>();

            if (item == null)
            {
                Console.WriteLine("请输入参数");
                PrintMenu();
                return;
            }

            Console.WriteLine("正在修改域名记录:" + item.SubDomain + "." + item.DomainName);

            DnsPodConfiguration configuration = new DnsPodConfiguration
            {
                Token = item.Token
            };
            DnsPodClient client = new DnsPodClient(new HttpClient(), configuration);
            DnsPodRecord record = new DnsPodRecord(client);

            //如果用户没有输入RecordId,则通过List接口获取
            if (item.RecordId == 0)
            {
                item.RecordId = Convert.ToInt32(record.List(item.DomainName).records.FirstOrDefault(r => r.name == item.SubDomain)?.id);
            }

            if (record.Modify(item.DomainName, item.RecordId, item.Value, item.SubDomain, item.RecordType))
            {
                Console.WriteLine("修改完成!");
            }
            else
            {
                Console.WriteLine("修改失败!");
            }
        }
Exemple #2
0
        /// <summary>
        /// 批更新 * 的泛解析
        /// 返回为true时表示全部更新成功,否则就是还有没有更新的
        /// </summary>
        /// <param name="ip">新的IP地址</param>
        /// <param name="autoCreate">当 泛解板不存在时是否自动创建</param>
        private bool BatchVast(string ip, bool autoCreate = false)
        {
            //var ip = "127.1.1.1";
            var subDomain = "*";
            //var isAutoCreate = true; //如果没有则创建
            var     api    = new DnsPodDomain();
            dynamic result = api.List(new { keyword = "" });//此处填写您域名的名称,为确保准确定位,请填写完整的域名,如:baidu.com

            //Console.WriteLine(result);
            if (result.status.code != 1)
            {
                Log.Warn($"查询域名列表时异常:[{result}]");
                return(false);
            }
            var domains = result.domains;
            var rst     = true; //更新结果为真

            _ups = 0;
            foreach (dynamic domain in domains)
            {
                var domainId = 0;
                domainId = domain.id;
                var record = new DnsPodRecord();
                var rdRst  = record.List(new
                {
                    domain_id  = domainId,
                    sub_domain = subDomain
                });
                var recordId = 0;
                if (rdRst.info.record_total == 0)
                {
                    //未有记录创建
                    if (autoCreate)
                    {
                        recordId = record.Create(new
                        {
                            domain_id   = domainId,
                            sub_domain  = subDomain,
                            record_type = "A",
                            record_line = "默认",
                            value       = ip,
                            //ttl = 300
                        });
                        Log.Info($"创建了新的泛解析{subDomain}.{domain.name},recordId={recordId}");
                    }
                }
                else
                {
                    foreach (dynamic rd in rdRst.records)
                    {
                        recordId = rd.id;
                        if (rd.name == subDomain && rd.value != ip)
                        {
                            var dyo = record.UpdateDdns(domainId, recordId, subDomain, ip);
                            var val = Convert.ToInt32(dyo.status.code) == 1;
                            rst = rst && val;
                            if (val)
                            {
                                _ups++;
                            }
                            else
                            {
                                Log.Warn($"更新*.{domain.name}时失败,返回的消息是:[{dyo}]");
                            }
                        }
                        //Console.WriteLine($"did={domainId}    rid={recordId}  subDomain={subDomain}   ip={ip}");
                    }
                }
            }
            return(rst);
        }
Exemple #3
0
 public HomeController(IOptions <DDnsConfiguration> config, DnsPodRecord dnsPodRecord)
 {
     configuration = config.Value;
     record        = dnsPodRecord;
 }