Пример #1
0
        /// <summary>
        /// Delete a previously created ManagedZone.
        /// Documentation https://developers.google.com/dns/v1/reference/managedZones/delete
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <param name="managedZone">Identifies the managed zone addressed by this request. Can be the managed zone name or id.</param>
        public static void Delete(DnsService service, string project, string managedZone)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (managedZone == null)
                {
                    throw new ArgumentNullException(managedZone);
                }

                // Make the request.
                service.ManagedZones.Delete(project, managedZone).Execute();
            }
            catch (Exception ex)
            {
                throw new Exception("Request ManagedZones.Delete failed.", ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Fetch the representation of an existing Change.
        /// Documentation https://developers.google.com/dns/v1/reference/changes/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <param name="managedZone">Identifies the managed zone addressed by this request. Can be the managed zone name or id.</param>
        /// <param name="changeId">The identifier of the requested change, from a previous ResourceRecordSetsChangeResponse.</param>
        /// <returns>ChangeResponse</returns>
        public static Change Get(DnsService service, string project, string managedZone, string changeId)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (managedZone == null)
                {
                    throw new ArgumentNullException(managedZone);
                }
                if (changeId == null)
                {
                    throw new ArgumentNullException(changeId);
                }

                // Make the request.
                return(service.Changes.Get(project, managedZone, changeId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Changes.Get failed.", ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Create a new ManagedZone.
        /// Documentation https://developers.google.com/dns/v2beta1/reference/managedZones/create
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <param name="body">A valid Dns v2beta1 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ManagedZoneResponse</returns>
        public static ManagedZone Create(DnsService service, string project, ManagedZone body, ManagedZonesCreateOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Building the initial request.
                var request = service.ManagedZones.Create(body, project);

                // Applying optional parameters to the request.
                request = (ManagedZonesResource.CreateRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request ManagedZones.Create failed.", ex);
            }
        }
Пример #4
0
        static async Task Main(string[] args)
        {
            IEnvVarReader           envVarReader            = new EnvVarReader();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            try
            {
                var service = new DnsService(envVarReader);

                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    Console.WriteLine("Cancel event triggered");
                    cancellationTokenSource
                    .Cancel(false);

                    eventArgs.Cancel = true;
                };

                await service.Start(cancellationTokenSource.Token).ConfigureAwait(false);

                service.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("DNS Server was stopped successfully.");
        }
Пример #5
0
        /// <summary>
        /// Enumerate Operations for the given ManagedZone.
        /// Documentation https://developers.google.com/dns/v2beta1/reference/managedZoneOperations/list
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <param name="managedZone">Identifies the managed zone addressed by this request.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ManagedZoneOperationsListResponseResponse</returns>
        public static ManagedZoneOperationsListResponse List(DnsService service, string project, string managedZone, ManagedZoneOperationsListOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (managedZone == null)
                {
                    throw new ArgumentNullException(managedZone);
                }

                // Building the initial request.
                var request = service.ManagedZoneOperations.List(project, managedZone);

                // Applying optional parameters to the request.
                request = (ManagedZoneOperationsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request ManagedZoneOperations.List failed.", ex);
            }
        }
Пример #6
0
        // This service creates a Dns server
        public static void Main()
        {
            // Initialize logging
            Logger.Initialize(new DebugLogger(), LoggerLevel.Debug);

            // Create the Dns server
            DnsService DnsServer = new DnsService();

            // Set the device server name and Dns suffix offered to client
            DnsServer.ServerName = "example";
            DnsServer.DnsSuffix  = "iot.local";

            // Sets interface ip address
            DnsServer.InterfaceAddress = IPAddress.GetDefaultLocalAddress();

            // Add a resource record to the zone table
            Answer record = new Answer();

            record.Domain = string.Concat(DnsServer.ServerName, ".", DnsServer.DnsSuffix);
            record.Class  = RecordClass.IN;
            record.Type   = RecordType.A;
            record.Ttl    = 60;
            record.Record = new ARecord(DnsServer.InterfaceAddress.ToString());
            DnsServer.ZoneFile.Add(record);

            // Enable Dns server to relay requests that can not be looked up locally to another Dns server.
            DnsServer.PrimaryServer = "8.8.8.8";
            DnsServer.IsProxy       = true;

            // Starts Dns service
            DnsServer.Start();
        }
Пример #7
0
        /// <summary>
        /// Create a new ManagedZone.
        /// Documentation https://developers.google.com/dns/v1/reference/managedZones/create
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <param name="body">A valid Dns v1 body.</param>
        /// <returns>ManagedZoneResponse</returns>
        public static ManagedZone Create(DnsService service, string project, ManagedZone body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Make the request.
                return(service.ManagedZones.Create(body, project).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request ManagedZones.Create failed.", ex);
            }
        }
Пример #8
0
        /// <summary>
        /// Fetch the representation of an existing Project.
        /// Documentation https://developers.google.com/dns/v2beta1/reference/projects/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ProjectResponse</returns>
        public static Project Get(DnsService service, string project, ProjectsGetOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Building the initial request.
                var request = service.Projects.Get(project);

                // Applying optional parameters to the request.
                request = (ProjectsResource.GetRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Projects.Get failed.", ex);
            }
        }
Пример #9
0
        public MainPageViewModel()
        {
            _dnsProviderUrl         = Properties.Resources.ShecanDnsProvider;
            _dnsResolvingError      = "Unable to fetch IP addresses!";
            _offlineStateError      = "You are offline.";
            _dnsService             = new DnsService();
            _dnsService.DnsChanged += OnDnsChanged;

            RegisterCommands();
            SetStatus();
        }
        public GoogleDnsProvider(GoogleDnsOptions options)
        {
            var jsonString = Encoding.UTF8.GetString(Convert.FromBase64String(options.KeyFile64));
            var credential = GoogleCredential.FromJson(jsonString).CreateScoped(DnsService.Scope.NdevClouddnsReadwrite);

            // Create the service.
            _dnsService = new DnsService(new BaseClientService.Initializer {
                HttpClientInitializer = credential
            });
            _credsParameters = NewtonsoftJsonSerializer.Instance.Deserialize <JsonCredentialParameters>(jsonString);
        }
Пример #11
0
        private static async Task GetHostEntryAsync()
        {
            var dnsService       = new DnsService();
            var googleHostResult = await Task.Factory.FromAsync((callback, stateObject) => dnsService.BeginGetHostEntry(GoogleHost, callback, stateObject), dnsService.EndGetHostEntry, null);

            Console.WriteLine($"Result from async/await: {GoogleHost} - {FormatHostEntry(googleHostResult)}");

            var yahooHostResult = await Task.Factory.FromAsync((callback, stateObject) => dnsService.BeginGetHostEntry(YahooHost, callback, stateObject), dnsService.EndGetHostEntry, null);

            Console.WriteLine($"Result from async/await: {YahooHost} - {FormatHostEntry(yahooHostResult)}");
        }
Пример #12
0
        public TransIp(
            LookupClientProvider dnsClient,
            ILogService log,
            IProxyService proxy,
            ISettingsService settings,
            DomainParseService domainParser,
            TransIpOptions options) : base(dnsClient, log, settings)
        {
            var auth = new AuthenticationService(options.Login, options.PrivateKey.Value, proxy);

            _dnsService   = new DnsService(auth, proxy);
            _domainParser = domainParser;
        }
Пример #13
0
        public void Query_Google_Co_Uk_For_NS_Records()
        {
            var dnsService = new DnsService();

            var queryResult = dnsService.GetDnsEntries("test.cocktail.local", DnsRecordType.A);
            Console.WriteLine();
            Console.Write("new byte[] { ");
            for (int i = 0; i < queryResult.PacketContent.Length; i++)
            {
                Console.Write("{0}, ", queryResult.PacketContent[i]);
            }
            Console.Write(" } ");
        }
Пример #14
0
        public BasicHost Host(string value, HostsManager hostsManager)
        {
            string[] splits    = value.Split('/');
            string   siteValue = splits[0];
            string   hostValue = splits[1];

            if (this.hostAliasesCache.ContainsKey(hostValue.ToLower()))
            {
                hostValue = this.hostAliasesCache[hostValue.ToLower()];
            }

            int       _tempIntValue;
            IPAddress hostAddress;

            if (!int.TryParse(hostValue, out _tempIntValue))
            {
                hostAddress = DnsService.Lookup(siteValue + hostValue);
            }
            else
            {
                IPAddress siteAddress;
                lock (hostsCacheLock) {
                    if (hostsCache.ContainsKey(siteValue))
                    {
                        siteAddress = hostsCache[siteValue];
                    }
                    else
                    {
                        siteAddress = DnsService.Lookup(siteValue + specialHostsConfig.DefaultDnsLookupSuffix);
                        hostsCache.Add(siteValue, siteAddress);
                    }
                }

                byte[] siteAddressBytes = siteAddress.GetAddressBytes();
                siteAddressBytes[3] = byte.Parse(hostValue);
                hostAddress         = new IPAddress(siteAddressBytes);
            }

            String lastOctet = hostAddress.GetAddressBytes()[3].ToString();

            if (specialHostConfigsCache.ContainsKey(lastOctet))
            {
                return(new ServiceGroupedDnsHost(hostAddress, specialHostConfigsCache[lastOctet].DisplayName, siteValue, specialHostConfigsCache[lastOctet].VncHostParams, specialHostConfigsCache[lastOctet].WebHostParams.ToArray()));
            }
            else
            {
                return(new GroupedDnsHost(hostAddress, "." + lastOctet, siteValue));
            }
        }
Пример #15
0
        private static void GetHostEntryIAsyncResultPattern()
        {
            DnsService dnsService = new DnsService();

            dnsService.BeginGetHostEntry(GoogleHost, googleAsyncResult =>
            {
                var googleHostResult = dnsService.EndGetHostEntry(googleAsyncResult);
                Console.WriteLine($"Result from IAsyncResultPattern: {GoogleHost} - {FormatHostEntry(googleHostResult)}");
                dnsService.BeginGetHostEntry(YahooHost, yahooAsyncResult =>
                {
                    var yahooHostResult = dnsService.EndGetHostEntry(yahooAsyncResult);
                    Console.WriteLine($"Result from IAsyncResultPattern: {YahooHost} - {FormatHostEntry(yahooHostResult)}");
                }, null);
            }, null);
        }
Пример #16
0
        private CloudDnsService CreateDnsService(ILogService log)
        {
            GoogleCredential credential;

            using (var stream = new FileStream(_options.ServiceAccountKeyPath, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream);
            }

            var dnsService = new DnsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "Win ACME",
            });

            return(new CloudDnsService(dnsService));
        }
Пример #17
0
        /// <summary>
        /// Fetch the representation of an existing Project.
        /// Documentation https://developers.google.com/dns/v1/reference/projects/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dns service.</param>
        /// <param name="project">Identifies the project addressed by this request.</param>
        /// <returns>ProjectResponse</returns>
        public static Project Get(DnsService service, string project)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Make the request.
                return(service.Projects.Get(project).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Projects.Get failed.", ex);
            }
        }
Пример #18
0
        private static async Task <HttpResponseMessage> NicUpdate(string hostname, string myip)
        {
            try
            {
                var hostAddress = await DnsService.GetHostAddress(hostname);

                var success   = hostAddress.Item1;
                var ipAddress = hostAddress.Item2;
                if (!success)
                {
                    Log.Error($"nohost {hostname}");
                    return(ReturnStatus("nohost"));
                }

                var newIp = IPAddress.Parse(myip);
                if (newIp.AddressFamily != AddressFamily.InterNetwork)
                {
                    Log.Error($"badip {newIp}");
                    return(ReturnStatus("badip"));
                }

                if (Equals(hostAddress.Item2, newIp))
                {
                    Log.Information($"nochg {hostname} {ipAddress} {newIp}");
                    return(ReturnStatus($"nochg {ipAddress}"));
                }

                Route53Service.UpdateRoute53Record(hostname, newIp);

                Log.Information($"good {hostname} {ipAddress} {newIp}");
                return(ReturnStatus($"good {newIp}"));
            }
            catch (Exception ex)
            {
                Log.Fatal($"911 {hostname} {IPAddress.Parse(myip)} {ex.Message} {ex.StackTrace}");
                return(ReturnStatus("911"));
            }
        }
 protected GcdCmdlet(DnsService service)
 {
     Service = service ?? new DnsService(GetBaseClientServiceInitializer());
 }
Пример #20
0
 public CloudDnsService(DnsService client)
 {
     _client = client;
 }
 protected GcdCmdlet(DnsService service)
 {
     Service = service ?? new DnsService(GetBaseClientServiceInitializer());
 }
Пример #22
0
 public Host.BasicHost Host(string value, HostsManager hostsManager)
 {
     return(new DnsBasicHost(DnsService.Lookup(value), value));
 }