private static void SetDns() { ILog _log = LogManager.GetLogger(typeof(Program)); LogManager.Configure("logs\\log.txt", 1024, false); int success = 0; try { Config cfg = Config.Load("config.json"); DnspodClient client = new DnspodClient(cfg.email, cfg.password); DomainList list = client.GetDomains(); Dictionary<string, SimpleDDNS.Clients.Dnspod.Domain> domainDict = list.GetDomainDict(); if (cfg.domains != null) { for (int i = 0; i < cfg.domains.Count; i++) { if (cfg.domains[i].records != null && cfg.domains[i].records.Count > 0 && domainDict.ContainsKey(cfg.domains[i].name)) { SimpleDDNS.Clients.Dnspod.Domain d = domainDict[cfg.domains[i].name]; RecordList rlist = client.GetRecords(d.id); if (rlist != null && rlist.records != null) { Dictionary<string, SimpleDDNS.Clients.Dnspod.Record> records = rlist.GetRecordDict(); for (int j = 0; j < cfg.domains[i].records.Count; j++) { Record r = cfg.domains[i].records[j]; if (records.ContainsKey(r.name)) { string value = GetIP(r.index); if (r.ip == IPType.internet) { value = GetIP(-1); } try { RecordUpdate ru = client.UpdateRecord(d.id, records[r.name].id, r.name, value); if (ru != null && ru.status != null && ru.status.code == "1") { string msg = string.Format("成功解析{0}.{1} -> {2}", r.name, d.name, value); Console.WriteLine(msg); _log.Info(msg); success++; } } catch (Exception ex) { _log.Error(ex); } } } } } } } } catch (Exception ex) { _log.Error(ex); } Console.WriteLine("成功解析{0}个域名! 3秒钟后退出...", success); Thread.Sleep(3000); }
private static void Test() { DnspodClient client = new DnspodClient("*****@*****.**", ""); fastJSON.JSON.Instance.Parameters.EnableAnonymousTypes = true; Debug.WriteLine(fastJSON.JSON.Instance.ToJSON(client.GetDomains())); Debug.WriteLine(fastJSON.JSON.Instance.ToJSON(client.GetRecords(0))); }