Пример #1
0
        public static DescribeDomainRecordsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DescribeDomainRecordsResponse describeDomainRecordsResponse = new DescribeDomainRecordsResponse();

            describeDomainRecordsResponse.HttpResponse = _ctx.HttpResponse;
            describeDomainRecordsResponse.RequestId    = _ctx.StringValue("DescribeDomainRecords.RequestId");
            describeDomainRecordsResponse.TotalCount   = _ctx.LongValue("DescribeDomainRecords.TotalCount");
            describeDomainRecordsResponse.PageNumber   = _ctx.LongValue("DescribeDomainRecords.PageNumber");
            describeDomainRecordsResponse.PageSize     = _ctx.LongValue("DescribeDomainRecords.PageSize");

            List <DescribeDomainRecordsResponse.DescribeDomainRecords_Record> describeDomainRecordsResponse_domainRecords = new List <DescribeDomainRecordsResponse.DescribeDomainRecords_Record>();

            for (int i = 0; i < _ctx.Length("DescribeDomainRecords.DomainRecords.Length"); i++)
            {
                DescribeDomainRecordsResponse.DescribeDomainRecords_Record record = new DescribeDomainRecordsResponse.DescribeDomainRecords_Record();
                record.DomainName = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].DomainName");
                record.RecordId   = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].RecordId");
                record.RR         = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].RR");
                record.Type       = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].Type");
                record._Value     = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].Value");
                record.TTL        = _ctx.LongValue("DescribeDomainRecords.DomainRecords[" + i + "].TTL");
                record.Priority   = _ctx.LongValue("DescribeDomainRecords.DomainRecords[" + i + "].Priority");
                record.Line       = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].Line");
                record.Status     = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].Status");
                record.Locked     = _ctx.BooleanValue("DescribeDomainRecords.DomainRecords[" + i + "].Locked");
                record.Weight     = _ctx.IntegerValue("DescribeDomainRecords.DomainRecords[" + i + "].Weight");
                record.Remark     = _ctx.StringValue("DescribeDomainRecords.DomainRecords[" + i + "].Remark");

                describeDomainRecordsResponse_domainRecords.Add(record);
            }
            describeDomainRecordsResponse.DomainRecords = describeDomainRecordsResponse_domainRecords;

            return(describeDomainRecordsResponse);
        }
Пример #2
0
        static void Main(string[] args)
        {
            //检测配置文件
            SettingModel sm = new SettingModel();

            if (!File.Exists("c:/dotnetsettings/aliyunddns.xml"))
            {
                WarningLog("检测无配置文件,生成配置文件中");
                Object2Xml <SettingModel>("c:/dotnetsettings/", "aliyunddns.xml", sm);
                WarningLog("配置文件已生成,请配置参数后重启程序");
                System.Environment.Exit(0);
            }
            else
            {
                sm = Xml2Object <SettingModel>("c:/dotnetsettings/aliyunddns.xml");
                if (sm == null || string.IsNullOrEmpty(sm.RR) || string.IsNullOrEmpty(sm.DomainName) || string.IsNullOrEmpty(sm.AccessKey) || string.IsNullOrEmpty(sm.AccessSecret))
                {
                    WarningLog("参数配置不能为空,请检查配置文件");
                    System.Environment.Exit(0);
                }
            }
            WarningLog("参数初始化成功,开始监听端口IP");
            while (true)
            {
                try
                {
                    DefaultAcsClient client    = new DefaultAcsClient(DefaultProfile.GetProfile("", sm.AccessKey, sm.AccessSecret));
                    string           currentIP = new WebClient().DownloadString("https://echo-ip.starworks.cc");
                    InfoLog("当前IP:" + currentIP);
                    var domainRecords = client.GetAcsResponse(new DescribeDomainRecordsRequest
                    {
                        DomainName = sm.DomainName,
                        RRKeyWord  = sm.RR,
                    }).DomainRecords;
                    DescribeDomainRecordsResponse.DescribeDomainRecords_Record home_Record = domainRecords.First(x => x.RR == sm.RR);
                    if (home_Record._Value != currentIP)
                    {
                        client.GetAcsResponse(new UpdateDomainRecordRequest
                        {
                            RecordId = home_Record.RecordId,
                            RR       = home_Record.RR,
                            Type     = home_Record.Type,
                            _Value   = currentIP,
                            TTL      = home_Record.TTL,
                        });
                        WarningLog($"地址更改,从{home_Record._Value}改为{currentIP}");
                    }
                    else
                    {
                        InfoLog("IP无变更");
                    }
                }
                catch (Exception ex)
                {
                    WarningLog(ex.ToString());
                }

                Thread.Sleep(sm.CheckTime * 1000);
            }
        }