Пример #1
0
        public static String BindServerToSite(String computerName)
        {
            if (String.IsNullOrEmpty(computerName))
            {
                return(null);
            }
            Hashtable   siteTable = new Hashtable();
            IPHostEntry ip        = Dns.GetHostEntry(computerName);

            try {
                DirectoryEntry subnets = new DirectoryEntry($"LDAP://CN=Subnets,CN=Sites,{ConfigContext}");
                foreach (DirectoryEntry subnet in subnets.Children)
                {
                    DirectoryEntry site = new DirectoryEntry("LDAP://" + subnet.Properties[PropSiteObject].Value);
                    siteTable.Add(subnet.Properties[PropCN].Value, site.Properties[PropCN].Value);
                }
            } catch {
                return(null);
            }
            foreach (String Key in siteTable.Keys)
            {
                String[] tokens = Key.Split('/');
                if (ip.AddressList.Any(address => Networking.InSameSubnet(tokens[0], Convert.ToInt32(tokens[1]), address.ToString())))
                {
                    String S = (String)siteTable[Key];
                    return(S);
                }
            }
            return(null);
        }
Пример #2
0
        public static String BindServerToSite(String computerName)
        {
            if (String.IsNullOrEmpty(computerName))
            {
                return(null);
            }
            Hashtable   siteTable = new Hashtable();
            IPHostEntry ip        = Dns.GetHostEntry(computerName);

            try {
                DirectoryEntry subnets = new DirectoryEntry($"LDAP://CN=Subnets,CN=Sites,{ConfigContext}");
                foreach (DirectoryEntry subnet in subnets.Children)
                {
                    DirectoryEntry site = new DirectoryEntry("LDAP://" + subnet.Properties["siteObject"].Value);
                    siteTable.Add(subnet.Properties["cn"].Value, site.Properties["cn"].Value);
                }
            } catch {
                return(null);
            }
            return((from string key in siteTable.Keys let tokens = key.Split('/') where ip.AddressList.Any(address => Networking.InSameSubnet(tokens[0], Convert.ToInt32(tokens[1]), address.ToString())) select(String) siteTable[key]).FirstOrDefault());
        }