Пример #1
0
        private static void AddSDLandTLDParameters(string hostname, QuerystringParameters querystringParameters)
        {
            var pieces = PartsOfDNSRecord.ExtractFromHostname(hostname);

            querystringParameters.Add("SLD", pieces.SecondLevelDomain);
            querystringParameters.Add("TLD", pieces.TopLevelDomain);
        }
Пример #2
0
        public void SetHostEntry(string hostname, string address)
        {
            var querystringParameters = StartParametersForCommand("namecheap.domains.dns.setHosts");

            AddSDLandTLDParameters(hostname, querystringParameters);
            querystringParameters.Add("HostName1", PartsOfDNSRecord.GetSubdomain(hostname));
            querystringParameters.Add("RecordType1", "A");
            querystringParameters.Add("Address1", address);
            querystringParameters.Add("MXPref1", "10");   // only valid for MX records, though sample showed it being set
            querystringParameters.Add("TTL1", "180");
            querystringParameters.Add("EmailType", "OX"); // ?

            GetApiResult(querystringParameters);
        }
Пример #3
0
        public static PartsOfDNSRecord ExtractFromHostname(string hostname)
        {
            var addressPartsReversed = hostname.Split('.').Reverse();

            var result = new PartsOfDNSRecord()
            {
                Subdomain = "@",
                SecondLevelDomain = addressPartsReversed.Skip(1).First(),
                TopLevelDomain = addressPartsReversed.First()
            };

            if (addressPartsReversed.Count() > 2)
                result.Subdomain = string.Join(".", addressPartsReversed.Skip(2).Reverse());

            return result;
        }
Пример #4
0
        public static PartsOfDNSRecord ExtractFromHostname(string hostname)
        {
            var addressPartsReversed = hostname.Split('.').Reverse();

            var result = new PartsOfDNSRecord()
            {
                Subdomain         = "@",
                SecondLevelDomain = addressPartsReversed.Skip(1).First(),
                TopLevelDomain    = addressPartsReversed.First()
            };

            if (addressPartsReversed.Count() > 2)
            {
                result.Subdomain = string.Join(".", addressPartsReversed.Skip(2).Reverse());
            }

            return(result);
        }
Пример #5
0
        public string GetHostEntry(string hostname)
        {
            var querystringParameters = StartParametersForCommand("namecheap.domains.dns.getHosts");

            AddSDLandTLDParameters(hostname, querystringParameters);

            var subdomain = PartsOfDNSRecord.GetSubdomain(hostname);

            var result = GetApiResult(querystringParameters);

            var ns = GetNamecheapNamespace();

            var commandResponse = result.Root.Elements(ns + "CommandResponse").Single();
            var getHostsResult  = commandResponse.Elements(ns + "DomainDNSGetHostsResult").Single();
            var hosts           = getHostsResult.Elements(ns + "host");
            var host            = hosts.Where(h => h.Attribute("Name").Value == subdomain).Single();

            return(host.Attribute("Address").Value);
        }