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()); }