小编Ste*_*rby的帖子

验证IP地址的最佳方法是什么?

我有一个方法来验证参数IP地址.作为一个整体发展的新手,我想知道是否有更好的方法来做到这一点.

/// <summary>
/// Check IP Address, will accept 0.0.0.0 as a valid IP
/// </summary>
/// <param name="strIP"></param>
/// <returns></returns>
public Boolean CheckIPValid(String strIP)
{
    //  Split string by ".", check that array length is 3
    char chrFullStop = '.';
    string[] arrOctets = strIP.Split(chrFullStop);
    if (arrOctets.Length != 4)
    {
        return false;
    }
    //  Check each substring checking that the int value is less than 255 and that is char[] length is !> 2
    Int16 MAXVALUE = 255;
    Int32 temp; …
Run Code Online (Sandbox Code Playgroud)

c# ip

38
推荐指数
5
解决办法
6万
查看次数

WMI重启远程计算机

我在一个旧线程上找到了这个代码来关闭本地机器:

using System.Management;

void Shutdown()
{
    ManagementBaseObject mboShutdown = null;
    ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
    mcWin32.Get();

    // You can't shutdown without security privileges
    mcWin32.Scope.Options.EnablePrivileges = true;
    ManagementBaseObject mboShutdownParams =
             mcWin32.GetMethodParameters("Win32Shutdown");

    // Flag 1 means we want to shut down the system. Use "2" to reboot.
    mboShutdownParams["Flags"] = "1";
    mboShutdownParams["Reserved"] = "0";
    foreach (ManagementObject manObj in mcWin32.GetInstances())
    {
        mboShutdown = manObj.InvokeMethod("Win32Shutdown", 
                                       mboShutdownParams, null);
    }
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用类似的WMI方法重启标志"2"远程机器,我只有机器名,而不是IPaddress.

编辑:我目前有:

SearchResultCollection allMachinesCollected = machineSearch.FindAll();
Methods myMethods = new Methods();
string pcName;
ArrayList allComputers = …
Run Code Online (Sandbox Code Playgroud)

.net c# wmi shutdown

13
推荐指数
1
解决办法
2万
查看次数

Active Directory列表OU

我目前有这个代码,

        string defaultNamingContext;

        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
        defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        rootDSE = new DirectoryEntry("LDAP://" + defaultNamingContext);
        //DirectoryEntry domain = new DirectoryEntry((string)"LDAP://" + defaultNamingContext);

        DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,"(objectCategory=Organizational-Unit)", 
                                 null, SearchScope.Subtree);

        MessageBox.Show(rootDSE.Path.ToString());
        try
        {
            SearchResultCollection collectedResult = ouSearch.FindAll();
            foreach (SearchResult temp in collectedResult)
            {
                comboBox1.Items.Add(temp.Properties["name"][0]);
                DirectoryEntry ou = temp.GetDirectoryEntry();
            }
        }
Run Code Online (Sandbox Code Playgroud)

当我使用调试器时,我可以看到rootDSE.Path实际指向正确的位置,在这种情况下,DC=g-t-p,DC=Local但目录搜索器找不到任何结果.有人可以帮忙吗?

c# directoryservices ldap active-directory

6
推荐指数
1
解决办法
9532
查看次数

获取AD OU列表

我希望能够从Active Directory中提取当前OU的列表我已经在线查看一些示例代码,但是O似乎无法使其工作.

        string defaultNamingContext;

        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
        defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        DirectorySearcher ouSearch = new DirectorySearcher(rootDSE, "(objectClass=organizationalUnit)", 
            null, SearchScope.Subtree);

        MessageBox.Show(rootDSE.ToString());
        try
        {
            SearchResultCollection collectedResult = ouSearch.FindAll();
            foreach (SearchResult temp in collectedResult)
            {
                comboBox1.Items.Add(temp.Properties["name"][0]);
                DirectoryEntry ou = temp.GetDirectoryEntry();
            }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是提供商不支持搜索,无法搜索LDAP:// RootDSE任何想法?对于每个返回的搜索结果,我想将它们添加到组合框中.(不应该太难)

c# directoryservices active-directory

5
推荐指数
1
解决办法
9597
查看次数

OU的LDAP查询

对不起是一个超级痛苦的人,这一切都很新:(

已经有很多帮助,但似乎没有能够看到问题,我正在尝试使用所有当前OU的列表填充组合框,稍后将该OU中的每台机器发送一个关机命令.(获取AD OU列表和Active Directory列表OU)是我以前的Q.

        string defaultNamingContext;
        //TODO 0 - Acquire and display the available OU's
        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
        defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        DirectoryEntry entryToQuery = new DirectoryEntry ("LDAP://" + defaultNamingContext);
        MessageBox.Show(entryToQuery.Path.ToString());

        DirectorySearcher ouSearch = new DirectorySearcher(entryToQuery.Path);
        ouSearch.Filter = "(objectCatergory=organizationalUnit)";
        ouSearch.SearchScope = SearchScope.Subtree;
        ouSearch.PropertiesToLoad.Add("name");

        SearchResultCollection allOUS = ouSearch.FindAll();

        foreach (SearchResult oneResult in allOUS)
        {
            //comboBox1.Items.Add(oneResult.ToString());
            comboBox1.Items.Add(oneResult.Properties["name"][0]);
        }
Run Code Online (Sandbox Code Playgroud)

我已经完成并调试了我所知道的一切,搜索者没有获得任何结果,因此为什么组合框中没有填充任何内容.

c# directoryservices ldap active-directory

5
推荐指数
1
解决办法
6455
查看次数

如果optional.isPresent()则使用可选值作为方法参数

我有一个包含几个选项的对象,其中可选项不为null,我想将其值作为参数传递给需要多个参数的方法.

目前我有一个代码块,如下所示:

if (dealerRequest.getIsApproved().isPresent()) {                
    repository.updateDealerPartnerFinanceIsApproved(dealerRequest.getDealerId(), dealerRequest.getIsApproved().get());
}
if (dealerRequest.getIsOptedIn().isPresent()) {                
    repository.updateDealerPartnerFinanceOptedIn(dealerRequest.getDealerId(), dealerRequest.getIsOptedIn().get());
}
Run Code Online (Sandbox Code Playgroud)

我知道检查该值是存在的,然后稍后获取它比以前的空检查更有用; 但是我不知道在这种情况下如何使用它们呢?

理想情况下,我会将.map()作为我仓库中方法的可选项,但后来我不知道如何传递(如果可以的话)第二个参数?有更简洁的方法吗?

java optional java-8

2
推荐指数
1
解决办法
841
查看次数

标签 统计

c# ×5

active-directory ×3

directoryservices ×3

ldap ×2

.net ×1

ip ×1

java ×1

java-8 ×1

optional ×1

shutdown ×1

wmi ×1