Пример #1
0
        public void CNameRecordMustExist()
        {
            var result = DnsServers.Resolve <CNameRecord>("mail.google.com").First();

            Console.WriteLine(result);
            Assert.IsNotEmpty(result.Value);
        }
Пример #2
0
        public void DomainsMustPass(string name)
        {
            var res = DnsServers.Resolve(name).ToList();

            Assert.IsNotNullOrEmpty(res.First().IPAddress.ToString());
            Console.WriteLine(string.Join(Environment.NewLine, res.Select(s => s.IPAddress)));
        }
Пример #3
0
        public void CorrectANameForCodeProject()
        {
            var response = DnsServers.Resolve("codeproject.com").ToList();

            // check the response
            Assert.AreEqual(1, response.Count);
            Assert.AreEqual(IPAddress.Parse("76.74.234.210"), response.First().IPAddress);
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            if (UpdateDNSonAllNetAdapters)
            {
                var vnet     = Get(Connection, Id);
                var vsubnets = GetVirtualSubNet.GetByvNetAll(Id, Connection);



                foreach (var vsubnet in vsubnets)
                {
                    var netadapters = GetVirtualNetAdapter.GetbyvSubnetAll(vsubnet.Id, Connection);

                    foreach (var netadapter in netadapters)
                    {
                        var job = UpdateVirtualNetAdapter.UpdateDNSonNetAdapter(netadapter.Id, vnet.DnsServers, Connection);

                        if (Wait)
                        {
                            WriteObject(WaitJobFinished(job.Id, Connection));
                        }
                        else
                        {
                            WriteObject(job);
                        }
                    }
                }
            }
            else
            {
                var vnet = Get(Connection, Id);



                if (!string.IsNullOrEmpty(Name))
                {
                    vnet.Name = Name;
                }
                if (DnsServers != null)
                {
                    vnet.DnsServers = DnsServers.ToArray();
                }

                var job = Update(Connection, Id, vnet);

                if (Wait)
                {
                    WriteObject(WaitJobFinished(job.Id, Connection));
                }
                else
                {
                    WriteObject(job);
                }
            }
        }
Пример #5
0
        public void TextRecordsMustExist()
        {
            var result = Resolver.Lookup(new Request {
                RecursionDesired = true
            }.WithQuestion(new Question("google.com", DnsType.TXT)));
            var l    = DnsServers.Resolve <TXTRecord>("google.com");
            var list = result.Answers.Select(s => s.Record).OfType <TXTRecord>().Select(s => s.Value).OrderBy(o => o).ToList();

            Assert.True(result.Answers.Length > 1);
            Assert.IsTrue(list.SequenceEqual(l.Select(s => s.Value).OrderBy(o => o).ToList()));
        }
Пример #6
0
        public void RepeatedANameLookups()
        {
            Parallel.For(0, 10, i =>
            {
                // send the request
                var response = DnsServers.Resolve("codeproject.com").ToArray();

                // check the response
                Assert.AreEqual(1, response.Length);
            });
        }
Пример #7
0
        public void CorrectMXForCodeProjectCompare()
        {
            var result = DnsServers.Resolve <MXRecord>("codeproject.com", DnsType.MX, DnsClass.IN);

            var records = Resolver.MXLookup("codeproject.com", DnsServers.IP4.First());

            Assert.IsNotNull(records, "MXLookup returning null denoting lookup failure");
            Assert.IsTrue(records.Length > 0);

            Assert.IsTrue(records.All(a => result.Contains(a)));
            Assert.IsTrue(result.All(a => records.Contains(a)));
        }
Пример #8
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="adapter">Win32_NetworkAdapter</param>
        /// <param name="config">Win32_NetworkAdapterConfiguration</param>
        public NetworkAdapter(ManagementObject adapter, ManagementObject config) : this()
        {
            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            Name          = (string)adapter["NetConnectionID"];
            IsDhcpEnabled = (bool)config["DHCPEnabled"];
            string tmpIPAddress = ((string[])config["IPAddress"]).FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(tmpIPAddress))
            {
                IPAddress = IPAddress.Parse(tmpIPAddress);
            }
            string tmpSubnetMask = ((string[])config["IPSubnet"]).FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(tmpSubnetMask))
            {
                SubnetMask = IPAddress.Parse(tmpSubnetMask);
            }
            string tmpDefaultGateway = config["DefaultIPGateway"] == null ? null : ((string[])config["DefaultIPGateway"]).FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(tmpDefaultGateway) && tmpDefaultGateway != "0.0.0.0" && tmpDefaultGateway != tmpIPAddress)
            {
                DefaultGateway = IPAddress.Parse(tmpDefaultGateway);
            }
            string[] tmpDnsServers = config["DNSServerSearchOrder"] == null ? null : ((string[])config["DNSServerSearchOrder"]);
            if (tmpDnsServers != null && 0 < tmpDnsServers.Length)
            {
                foreach (var dns in tmpDnsServers.Select(dns => IPAddress.Parse(dns)))
                {
                    DnsServers.Add(dns);
                }
            }
        }
Пример #9
0
        private List <Error> ReadDeviceDefinitionsFromDirectory(
            string deviceDefinitionsDirectory)
        {
            var errors = new List <Error>();
            var deviceDefinitionFiles = new List <string>();

            if (Directory.Exists(deviceDefinitionsDirectory))
            {
                deviceDefinitionFiles =
                    Directory.EnumerateFiles(
                        deviceDefinitionsDirectory
                        )
                    .Where(x => x.Contains(DeviceFileExtension))
                    .ToList();
            }
            else
            {
                errors.Add(
                    Error.DirectoryNotFoundError(deviceDefinitionsDirectory)
                    );
            }

            foreach (var file in deviceDefinitionFiles)
            {
                var fileContents = File.ReadAllText(file);

                var jDoc =
                    JsonDocument.Parse(fileContents);

                foreach (var item in jDoc.RootElement.EnumerateObject())
                {
                    try
                    {
                        switch (item.Name.ToLower())
                        {
                        case "clients":
                            AddNetworkNodes <Client>(item.Value);
                            break;

                        case "contentservers":
                            AddNetworkNodes <ContentServer>(item.Value);
                            break;

                        case "dnsservers":
                            AddNetworkNodes <DnsServer>(item.Value);
                            break;

                        case "switches":
                            AddNetworkNodes <Switch>(item.Value);
                            break;

                        default:
                            break;
                        }
                        ;
                    }
                    catch (Exception ex)
                    {
                        errors.Add(
                            Error.GeneralException(ex)
                            );
                    }
                }
            }

            return(errors);

            void AddNetworkNodes <T>(
                JsonElement array)
            {
                var settings =
                    new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                };

                foreach (var item in array.EnumerateArray())
                {
                    switch (typeof(T))
                    {
                    case var x when x == typeof(Client):
                        Clients.Add(
                            JsonSerializer.Deserialize <Client>(
                                item.GetRawText(),
                                settings
                                )
                            );
                        break;

                    case var x when x == typeof(ContentServer):
                        ContentServers.Add(
                            JsonSerializer.Deserialize <ContentServer>(
                                item.GetRawText(),
                                settings
                                )
                            );
                        break;

                    case var x when x == typeof(DnsServer):
                        DnsServers.Add(
                            JsonSerializer.Deserialize <DnsServer>(
                                item.GetRawText(),
                                settings
                                )
                            );
                        break;

                    case var x when x == typeof(Switch):
                        Switches.Add(
                            JsonSerializer.Deserialize <Switch>(
                                item.GetRawText(),
                                settings
                                )
                            );
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            // register the subscription for this service if it has not been before
            // sebsequent call to register is redundent
            RegisterSubscriptionWithRdfeForRemoteApp();

            NetworkCredential         creds   = null;
            CollectionCreationDetails details = new CollectionCreationDetails()
            {
                Name = CollectionName,
                TemplateImageName = ImageName,
                Region            = Location,
                PlanName          = Plan,
                Description       = Description,
                CustomRdpProperty = CustomRdpProperty,
                Mode = CollectionMode.Apps
            };
            OperationResultWithTrackingId response = null;

            switch (ParameterSetName)
            {
            case DomainJoined:
            case AzureVNet:
            {
                creds            = Credential.GetNetworkCredential();
                details.VNetName = VNetName;

                if (SubnetName != null)
                {
                    if (!IsFeatureEnabled(EnabledFeatures.azureVNet))
                    {
                        ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                            string.Format(Commands_RemoteApp.LinkAzureVNetFeatureNotEnabledMessage),
                            String.Empty,
                            Client.Account,
                            ErrorCategory.InvalidOperation
                            );

                        ThrowTerminatingError(er);
                    }

                    details.SubnetName = SubnetName;
                    ValidateCustomerVNetParams(details.VNetName, details.SubnetName);

                    if (DnsServers != null)
                    {
                        details.DnsServers = DnsServers.Split(new char[] { ',' });
                    }

                    details.Region = Location;
                }

                details.AdInfo = new ActiveDirectoryConfig()
                {
                    DomainName         = Domain,
                    OrganizationalUnit = OrganizationalUnit,
                    UserName           = creds.UserName,
                    Password           = creds.Password,
                };
                break;
            }

            case NoDomain:
            default:
            {
                details.Region = Location;
                break;
            }
            }

            response = CallClient(() => Client.Collections.Create(false, details), Client.Collections);

            if (response != null)
            {
                TrackingResult trackingId = new TrackingResult(response);
                WriteObject(trackingId);
            }
        }
Пример #11
0
 public ResolverContext AddDnsServer(string ipAddress, int port = 53)
 {
     DnsServers.Add(new IPEndPoint(IPAddress.Parse(ipAddress), port));
     return(this);
 }
        /// <summary>
        /// Set the ip address properties of the <see cref="NetworkConnectionProperties"/> instance.
        /// </summary>
        /// <param name="properties">Element of the type <see cref="IPInterfaceProperties"/>.</param>
        private void SetIpProperties(IPInterfaceProperties properties)
        {
            var ipList = properties.UnicastAddresses;

            foreach (var ip in ipList)
            {
                if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                {
                    IPv4     = ip.Address.ToString();
                    IPv4Mask = ip.IPv4Mask.ToString();
                }
                else if (ip.Address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    if (string.IsNullOrEmpty(IPv6Primary))
                    {
                        IPv6Primary = ip.Address.ToString();
                    }

                    if (ip.Address.IsIPv6LinkLocal)
                    {
                        IPv6LinkLocal = ip.Address.ToString();
                    }
                    else if (ip.Address.IsIPv6SiteLocal)
                    {
                        IPv6SiteLocal = ip.Address.ToString();
                    }
                    else if (ip.Address.IsIPv6UniqueLocal)
                    {
                        IPv6UniqueLocal = ip.Address.ToString();
                    }
                    else if (ip.SuffixOrigin == SuffixOrigin.Random)
                    {
                        IPv6Temporary = ip.Address.ToString();
                    }
                    else
                    {
                        IPv6Global = ip.Address.ToString();
                    }
                }
            }

            foreach (var ip in properties.GatewayAddresses)
            {
                Gateways.Add(ip.Address.ToString());
            }

            foreach (var ip in properties.DhcpServerAddresses)
            {
                DhcpServers.Add(ip.ToString());
            }

            foreach (var ip in properties.DnsAddresses)
            {
                DnsServers.Add(ip.ToString());
            }

            foreach (var ip in properties.WinsServersAddresses)
            {
                WinsServers.Add(ip.ToString());
            }
        }
        public override void ExecuteCmdlet()
        {
            // register the subscription for this service if it has not been before
            // sebsequent call to register is redundent
            RegisterSubscriptionWithRdfeForRemoteApp();

            NetworkCredential         creds   = null;
            CollectionCreationDetails details = new CollectionCreationDetails()
            {
                Name = CollectionName,
                TemplateImageName = ImageName,
                Region            = Location,
                PlanName          = Plan,
                Description       = Description,
                CustomRdpProperty = CustomRdpProperty,
                Mode = (ResourceType == null || ResourceType == CollectionMode.Unassigned) ? CollectionMode.Apps : ResourceType.Value
            };
            OperationResultWithTrackingId response = null;


            if (ParameterSetName == "AzureVNet")
            {
                details.VNetName   = VNetName;
                details.SubnetName = SubnetName;
                ValidateCustomerVNetParams(details.VNetName, details.SubnetName);

                if (DnsServers != null)
                {
                    details.DnsServers = DnsServers.Split(new char[] { ',' });
                }

                if (!String.IsNullOrWhiteSpace(Domain) || Credential != null)
                {
                    if (String.IsNullOrWhiteSpace(Domain) || Credential == null)
                    {
                        // you supplied either a domain or a cred, but not both.
                        ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                            Commands_RemoteApp.InvalidADArguments,
                            String.Empty,
                            Client.Collections,
                            ErrorCategory.InvalidArgument
                            );

                        ThrowTerminatingError(er);
                    }

                    creds          = Credential.GetNetworkCredential();
                    details.AdInfo = new ActiveDirectoryConfig()
                    {
                        DomainName         = Domain,
                        OrganizationalUnit = OrganizationalUnit,
                        UserName           = creds.UserName,
                        Password           = creds.Password,
                    };
                }
            }
            else
            {
                if (String.IsNullOrEmpty(details.Region))
                {
                    ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                        Commands_RemoteApp.InvalidLocationArgument,
                        String.Empty,
                        Client.Collections,
                        ErrorCategory.InvalidArgument
                        );

                    ThrowTerminatingError(er);
                }
            }

            response = CallClient(() => Client.Collections.Create(false, details), Client.Collections);

            if (response != null)
            {
                TrackingResult trackingId = new TrackingResult(response);
                WriteObject(trackingId);
            }
        }
Пример #14
0
        public void CorrectCNameForGmail()
        {
            var result = DnsServers.Resolve <CNameRecord>("mail.google.com").First();

            Assert.AreEqual(result.Value, "googlemail.l.google.com");
        }