当前位置: 首页>>代码示例>>C#>>正文


C# TargetInfo.GetAddress方法代码示例

本文整理汇总了C#中TargetInfo.GetAddress方法的典型用法代码示例。如果您正苦于以下问题:C# TargetInfo.GetAddress方法的具体用法?C# TargetInfo.GetAddress怎么用?C# TargetInfo.GetAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TargetInfo的用法示例。


在下文中一共展示了TargetInfo.GetAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Check

        public TargetCheckingResult Check(TargetInfo targetInfo)
        {
            var targetAvailable = false;
            string errorMessage = null;
            try
            {
                new WMIConnectionProvider("cimv2").Connect(targetInfo);
                targetAvailable = true;
            }
            catch (UnauthorizedAccessException)
            {
                errorMessage =
                    string.Format(
                        "Unable to connect to host. The target machine ({0}) denied access to the user ({1}).",
                        targetInfo.GetAddress(), targetInfo.credentials.GetFullyQualifiedUsername());
            }
            catch (CannotConnectToHostException ex)
            {
                errorMessage =
                    string.Format(
                        "Unable to connect to host. The target machine ({0}) returned the following error: {1}.",
                        targetInfo.GetAddress(), ex.Message);
            }
            catch (Exception ex1)
            {
                errorMessage =
                    string.Format(
                        "An unknown error occurred while trying to connect to host ({0}): {1}.",
                        targetInfo.GetAddress(), ex1.Message);
            }

            return new TargetCheckingResult() { IsTargetAvailable = targetAvailable, ErrorMessage = errorMessage };
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:33,代码来源:WindowsTargetChecker.cs

示例2: Connect

 /// <summary>
 /// Tries to connect to the host specified. The connection is used WMI.
 /// </summary>
 /// <param name="target">Host to Connect</param>
 public void Connect(TargetInfo target)
 {
     try
     {
         Credentials credentials = target.IsLocalTarget() ? null : target.credentials;
         ConnectionOptions options = this.GetConnectionOptions(credentials);
         
         this.ConnectionScope = this.GetManagementScope(options, target.GetAddress());
     }
     catch (UnauthorizedAccessException unauthorizedAccessException)
     {
         string errorMessage = string.Format(INVALID_CREDENTIALS_ERROR_MESSAGE, target.GetAddress(), target.credentials.GetDomain(), target.credentials.GetUserName());
         throw new InvalidCredentialsException(target.credentials, errorMessage, unauthorizedAccessException);
     }
     catch (COMException comException)
     {
         string errorMessage = string.Format(PROVIDER_CONNECTING_ERROR_MESSAGE, target.GetAddress(), comException.Message);
         throw new CannotConnectToHostException(target, errorMessage, comException);
     }
     catch (Exception ex)
     {
         string errorMessage = string.Format(PROVIDER_CONNECTING_ERROR_MESSAGE, target.GetAddress(), ex.Message);
         throw new ProbeException(errorMessage, ex);
     }
 }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:29,代码来源:FileConnectionProvider.cs

示例3: Check

        public TargetCheckingResult Check(TargetInfo targetInfo)
        {
            string errorMessage = null;
            var targetAvailable = false;
            var sshConnectionProvider = new SSHConnectionProvider();
            try
            {
                sshConnectionProvider.Connect(targetInfo);
                targetAvailable = true;
            }
            catch (SshConnectingException sshException)
            {
                errorMessage = sshException.Message;
            }
            catch (Exception genericException)
            {
                errorMessage =
                    string.Format(
                        "An unknown error occurred while trying to connect to target machine ({0}): {1}.",
                        targetInfo.GetAddress(), genericException.Message);
            }
            finally
            {
                sshConnectionProvider.Disconnect();
            }

            return new TargetCheckingResult() { IsTargetAvailable = targetAvailable, ErrorMessage = errorMessage };
        }
开发者ID:ywcsz,项目名称:modSIC,代码行数:28,代码来源:UnixTargetChecker.cs

示例4: GetSystemInformationFrom

        public SystemInformation GetSystemInformationFrom(TargetInfo target)
        {
            var sshExec = new SshExec(target.GetAddress(), target.credentials.GetUserName(), target.credentials.GetPassword());
            sshExec.Connect(target.GetPort());

            var collectedUnixSystemInformation = SystemInformationCollector.getSysInfo(sshExec);

            return this.CreateSystemInformationInstance(collectedUnixSystemInformation);
        }
开发者ID:ywcsz,项目名称:modSIC,代码行数:9,代码来源:UnixSystemInformationService.cs

示例5: GetSystemInformationFrom

        public SystemInformation GetSystemInformationFrom(TargetInfo target)
        {
            var hostAddress = target.GetAddress();
            var username = target.credentials.GetUserName();
            var password = target.credentials.GetPassword();

            var commandRunner = new SshCommandLineRunner(hostAddress, username, password, target.GetPort());
            var collectedUnixSystemInformation = SystemInformationCollector.getSysInfo(commandRunner);
            return CreateSystemInformationInstance(collectedUnixSystemInformation);
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:10,代码来源:UnixSystemInformationService.cs

示例6: Should_be_possible_to_get_files_from_given_directory_path_using_FileContentSystemDataSource

        public void Should_be_possible_to_get_files_from_given_directory_path_using_FileContentSystemDataSource()
        {
            FakeTarget = ProbeHelper.CreateFakeTarget();
            var fileContentSystemDataSource = new FileContentSystemDataSource(FakeTarget.GetAddress());
            /*IList<string> returnedFiles = fileContentSystemDataSource.GetValues(GetFakeWmiParameters());

            Assert.AreEqual(2, returnedFiles.Count, "The returned file count is unexpected.");
            Assert.AreEqual(FAKE_DIR_PATH, returnedFiles[0], "The fake directory was unexpected.");
            Assert.AreEqual(FAKE_FILE_PATH, returnedFiles[1], "The fake file path was unexpected."); */
        }
开发者ID:ywcsz,项目名称:modSIC,代码行数:10,代码来源:FileContentObjectCollectorTests.cs

示例7: Connect

        public virtual void Connect(TargetInfo target)
        {
            var connectionPort = target.GetPort(ConnectionType.Telnet);
            this.TelnetConnection = new TelnetConnection(target.GetAddress(), connectionPort);
            this.TelnetConnection.TimeOutLoginMs = 1000;
            this.TelnetConnection.TimeOutReadMs = 30000;
            this.TelnetConnection.CiscoLogin(target.credentials.GetUserName(), target.credentials.GetPassword());

            string adminPass = target.credentials.GetAdminPassword();
            if (!String.IsNullOrEmpty(adminPass))
                this.TelnetConnection.CiscoEnable(adminPass);
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:12,代码来源:CiscoIOSConnectionProvider.cs

示例8: Connect

 public virtual void Connect(TargetInfo target)
 {
     this.SshCommandLineRunner = CreateSshCommandLineRunner(target);
     try
     {
         this.SshCommandLineRunner.Connect();
     }
     catch (Exception ex)
     {
         throw new SshConnectingException(
             string.Format(
                 "Unable to connect to target machine {0} through port {1} using the user {2}. Check the target address (or host name), port number and that ssh service is running at target machine. Error Message: '{3}'",
                 target.GetAddress(), target.GetPort(), target.credentials.GetFullyQualifiedUsername(), ex.Message));
     }
 }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:15,代码来源:SSHConnectionProvider.cs

示例9: Connect

 public virtual void Connect(TargetInfo target)
 {
     this.CreateSSHExec(target);
     try
     {
         this.SSHExec.Connect(target.GetPort());
     }
     catch (JSchException ex)
     {
         throw new SshConnectingException(
             string.Format(
                 "Unable to connect to target machine {0} through port {1} using the user {2}. Check the target address (or host name), port number and that ssh service is running at target machine.",
                 target.GetAddress(), target.GetPort(), target.credentials.GetFullyQualifiedUsername()));
     }
 }
开发者ID:ywcsz,项目名称:modSIC,代码行数:15,代码来源:SSHConnectionProvider.cs

示例10: CreateWmiDataProviderForFileSearching

        public static WmiDataProvider CreateWmiDataProviderForFileSearching(TargetInfo targetInfo)
        {
            var wmiNamespace = getNamespaceForTargetAddress(targetInfo.GetAddress());

            var username = string.Empty;
            var password = string.Empty;
            if (targetInfo.IsThereCredential())
            {
                username = targetInfo.credentials.GetFullyQualifiedUsername();
                password = targetInfo.credentials.GetPassword();
            }
            
            var connectionOptions = CreateConnectionOptions(username, password);

            var wmiConnectionScope = new ManagementScope(wmiNamespace, connectionOptions);
            wmiConnectionScope.Connect();

            return new WmiDataProvider(wmiConnectionScope);
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:19,代码来源:WmiDataProviderFactory.cs

示例11: Connect

        public void Connect(TargetInfo target)
        {
            var binding = new BasicHttpBinding();
            
            binding.MaxBufferSize = 2147483647;
            binding.MaxBufferPoolSize = 2147483647;
            binding.MaxReceivedMessageSize = 2147483647;

            binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
            binding.ReaderQuotas.MaxStringContentLength = 2147483647;
            binding.ReaderQuotas.MaxArrayLength = 2147483647;
            
            //binding.MaxReceivedMessageSize = 1000000;


            binding.SendTimeout = TimeSpan.FromMinutes(10);
            this.connectionProvider = new ScanWSClient(
                binding,
                new System.ServiceModel.EndpointAddress(target.GetAddress()));
            connectionProvider.Open();
            
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:22,代码来源:CodeControlConnectionProvider.cs

示例12: GetRegKeyDACLs

        public virtual Dictionary<string, uint> GetRegKeyDACLs(TargetInfo targetInfo, string regHive, string regKey)
        {
            IntPtr token = LogOn(targetInfo);
            var person = WindowsIdentity.Impersonate(token);
            RegistryKey remoteKey = null;
            try
            {
                remoteKey = this.TryToOpenRemoteKey(targetInfo, regHive, regKey);
            }
            finally
            {
                person.Undo();
            }

            try
            {
                var regKeyAccessControl = remoteKey.GetAccessControl(AccessControlSections.Access);
                var typeOfSID = typeof(System.Security.Principal.SecurityIdentifier);
                var DACLs = regKeyAccessControl.GetAccessRules(true, true, typeOfSID);

                var result = new Dictionary<string, uint>();
                foreach (RegistryAccessRule dacl in DACLs)
                {
                    var userDACL = (uint)dacl.RegistryRights;
                    if (userDACL <= Int32.MaxValue)
                    {
                        var userSid = dacl.IdentityReference.Value;
                        if (result.ContainsKey(userSid))
                            result[userSid] += userDACL;
                        else
                            result.Add(userSid, userDACL);
                    }
                }
                
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("An error occurred while trying to get effective rights on target '{0}':\r\n'{1}'", targetInfo.GetAddress(), ex.Message));
            }
            //finally
            //{
            //    person.Undo();
            //}          
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:45,代码来源:AccessControlListProvider.cs

示例13: GetAuditEventPolicies

        public virtual Dictionary<AuditEventPolicies, AuditEventStatus> GetAuditEventPolicies(TargetInfo targetInfo)
        {
            Dictionary<AuditEventPolicies, AuditEventStatus> retList = new Dictionary<AuditEventPolicies, AuditEventStatus>();

            LSA_UNICODE_STRING systemName = string2LSAUS(targetInfo.GetAddress());
            LSA_OBJECT_ATTRIBUTES objAttrs = new LSA_OBJECT_ATTRIBUTES();

            IntPtr policyHandle = IntPtr.Zero;
            IntPtr pAuditEventsInfo = IntPtr.Zero;
            IntPtr pAuditCategoryGuid = IntPtr.Zero;
            IntPtr pAuditSubCategoryGuids = IntPtr.Zero;
            IntPtr pAuditPolicies = IntPtr.Zero;

            UInt32 lretVal = LsaOpenPolicy(ref systemName, ref objAttrs, POLICY_VIEW_AUDIT_INFORMATION, out policyHandle);
            uint retVal = LsaNtStatusToWinError(lretVal);
            if (retVal != 0)
            {
                throw new System.ComponentModel.Win32Exception((int)retVal);
            }

            try
            {
                lretVal = LsaQueryInformationPolicy(policyHandle, POLICY_INFORMATION_CLASS.PolicyAuditEventsInformation, out pAuditEventsInfo);
                retVal = LsaNtStatusToWinError(lretVal);
                if (retVal != 0)
                {
                    throw new System.ComponentModel.Win32Exception((int)retVal);
                }

                //  EventAuditingOptions: The index of each array element corresponds to an audit event type value in the POLICY_AUDIT_EVENT_TYPE enumeration type.
                //  Each POLICY_AUDIT_EVENT_OPTIONS variable in the array can specify the following auditing options.
                //  POLICY_AUDIT_EVENT_UNCHANGED, POLICY_AUDIT_EVENT_SUCCESS, POLICY_AUDIT_EVENT_FAILURE, POLICY_AUDIT_EVENT_NONE
                POLICY_AUDIT_EVENTS_INFO myAuditEventsInfo = new POLICY_AUDIT_EVENTS_INFO();
                myAuditEventsInfo = (POLICY_AUDIT_EVENTS_INFO)Marshal.PtrToStructure(pAuditEventsInfo, myAuditEventsInfo.GetType());

                for (UInt32 policyAuditEventType = 0; policyAuditEventType < myAuditEventsInfo.MaximumAuditEventCount; policyAuditEventType++)
                {

                    pAuditCategoryGuid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GUID)));
                    if (!AuditLookupCategoryGuidFromCategoryId((POLICY_AUDIT_EVENT_TYPE)policyAuditEventType, pAuditCategoryGuid))
                    {
                        int causingError = GetLastError();
                        throw new System.ComponentModel.Win32Exception(causingError);
                    }

                    String categoryName = String.Empty;
                    AuditLookupCategoryName(pAuditCategoryGuid, ref categoryName);

                    UInt32 status = 0;
                    IntPtr itemPtr = new IntPtr(myAuditEventsInfo.EventAuditingOptions.ToInt64() + (Int64)policyAuditEventType * (Int64)Marshal.SizeOf(typeof(UInt32)));
                    status = (UInt32)Marshal.PtrToStructure(itemPtr, status.GetType());
                    retList.Add((AuditEventPolicies)policyAuditEventType, (AuditEventStatus)(status & 0x3));

                    Marshal.FreeHGlobal(pAuditCategoryGuid);
                    pAuditCategoryGuid = IntPtr.Zero;
                }
            }
            finally
            {
                if (pAuditEventsInfo != IntPtr.Zero)
                {
                    LsaFreeMemory(pAuditEventsInfo);
                }

                if (pAuditCategoryGuid != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pAuditCategoryGuid);
                }

                LsaClose(policyHandle);
            }

            return retList;
        }
开发者ID:JorgeHudson,项目名称:modSIC,代码行数:74,代码来源:AuditEventPolicyHelper.cs

示例14: GetPolAdtEv

        private string GetPolAdtEv(TargetInfo targetInfo)
        {
            string build = @"QUERY \\" + targetInfo.GetAddress() + @"\HKLM\Security\Policy\PolAdtEv\";
            string parms = @build;
            string output = string.Empty;
            string error = string.Empty;

            ProcessStartInfo psi = new ProcessStartInfo("reg.exe", parms);

            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError = true;
            psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            psi.UseShellExecute = false;
            var reg = Process.Start(psi);
            using (StreamReader myOutput = reg.StandardOutput)
            {
                output = myOutput.ReadToEnd();
            }
            using (StreamReader myError = reg.StandardError)
            {
                error = myError.ReadToEnd();
            }

            if (error != string.Empty)
                throw new Exception(error);

            output = output.Replace(@"HKEY_LOCAL_MACHINE\Security\Policy\PolAdtEv", string.Empty);
            output = output.Replace("(Default)", string.Empty);
            output = output.Replace("REG_NONE", string.Empty);
            output = output.Replace(Environment.NewLine, string.Empty);

            return output.Trim();
        }
开发者ID:JorgeHudson,项目名称:modSIC,代码行数:33,代码来源:AuditEventPolicyHelper.cs

示例15: GetAuditEventSubcategoriesPolicy

        public virtual Dictionary<AuditEventSubcategories, AuditEventStatus> GetAuditEventSubcategoriesPolicy(TargetInfo targetInfo)
        {
            Dictionary<AuditEventSubcategories, AuditEventStatus> retList = new Dictionary<AuditEventSubcategories, AuditEventStatus>();

            string target = @"\\" + targetInfo.GetAddress();
            LSA_UNICODE_STRING systemName = string2LSAUS(target);
            LSA_OBJECT_ATTRIBUTES objAttrs = new LSA_OBJECT_ATTRIBUTES();

            IntPtr policyHandle = IntPtr.Zero;
            IntPtr pAuditEventsInfo = IntPtr.Zero;
            IntPtr pAuditCategoryId = IntPtr.Zero;
            IntPtr pAuditSubCategoryGuids = IntPtr.Zero;
            IntPtr pAuditPolicies = IntPtr.Zero;

            UInt32 lretVal = LsaOpenPolicy(ref systemName, ref objAttrs, POLICY_VIEW_AUDIT_INFORMATION, out policyHandle);
            UInt32 retVal = LsaNtStatusToWinError(lretVal);

            if (retVal == (UInt32)0)
            {
                try
                {
                    lretVal = LsaQueryInformationPolicy(policyHandle, POLICY_INFORMATION_CLASS.PolicyAuditEventsInformation, out pAuditEventsInfo);
                    retVal = LsaNtStatusToWinError(lretVal);

                    if (retVal == 0)
                    {
                        POLICY_AUDIT_EVENTS_INFO myAuditEventsInfo = new POLICY_AUDIT_EVENTS_INFO();
                        myAuditEventsInfo = (POLICY_AUDIT_EVENTS_INFO)Marshal.PtrToStructure(pAuditEventsInfo, myAuditEventsInfo.GetType());

                        for (var policyAuditEventType = 0; policyAuditEventType < myAuditEventsInfo.MaximumAuditEventCount; policyAuditEventType++)
                        {
                            pAuditCategoryId = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GUID)));
                            if (!AuditLookupCategoryGuidFromCategoryId((POLICY_AUDIT_EVENT_TYPE)policyAuditEventType, pAuditCategoryId))
                            {
                                int causingError = GetLastError();
                                throw new System.ComponentModel.Win32Exception(causingError);
                            }

                            UInt32 nSubCats = 0;
                            pAuditSubCategoryGuids = IntPtr.Zero;
                            if (!AuditEnumerateSubCategories(pAuditCategoryId, false, ref pAuditSubCategoryGuids, out nSubCats))
                            {
                                int causingError = GetLastError();
                                throw new System.ComponentModel.Win32Exception(causingError);
                            }

                            Marshal.FreeHGlobal(pAuditCategoryId);
                            pAuditCategoryId = IntPtr.Zero;

                            pAuditPolicies = IntPtr.Zero;
                            if (nSubCats > 0)
                            {

                                if (!AuditQuerySystemPolicy(pAuditSubCategoryGuids, nSubCats, out pAuditPolicies))
                                {
                                    int causingError = GetLastError();
                                    throw new System.ComponentModel.Win32Exception(causingError);
                                }

                                for (var subcategoryIndex = 0; subcategoryIndex < nSubCats; subcategoryIndex++)
                                {
                                    AUDIT_POLICY_INFORMATION currentPolicy = new AUDIT_POLICY_INFORMATION();

                                    IntPtr itemPtr = new IntPtr(pAuditPolicies.ToInt64() + (Int64)subcategoryIndex * (Int64)Marshal.SizeOf(currentPolicy));
                                    currentPolicy = (AUDIT_POLICY_INFORMATION)Marshal.PtrToStructure(itemPtr, currentPolicy.GetType());

                                    String subCategoryName = String.Empty;
                                    Marshal.StructureToPtr(currentPolicy, itemPtr, true);
                                    AuditLookupSubCategoryName(itemPtr, ref subCategoryName);

                                    AuditEventSubcategories value;
                                    if (subcategoriesDictionary.TryGetValue(subCategoryName, out value))
                                    {
                                        retList.Add(value, (AuditEventStatus)(currentPolicy.AuditingInformation & 0x3));
                                    }
                                }

                                if (pAuditPolicies != IntPtr.Zero)
                                {
                                    AuditFree(pAuditPolicies);
                                    pAuditPolicies = IntPtr.Zero;
                                }
                            }

                            if (pAuditSubCategoryGuids != IntPtr.Zero)
                            {
                                AuditFree(pAuditSubCategoryGuids);
                                pAuditSubCategoryGuids = IntPtr.Zero;
                            }

                            nSubCats = 0;
                        }
                    }
                    else
                    {
                        throw new System.ComponentModel.Win32Exception((int)retVal);
                    }
                }
                finally
                {
//.........这里部分代码省略.........
开发者ID:ywcsz,项目名称:modSIC,代码行数:101,代码来源:AuditEventPolicyHelper.cs


注:本文中的TargetInfo.GetAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。