/// <summary> /// Allows you to pass an array of strings that contain the IP Addresses /// to grant. /// /// Wildcard IPs should use .* or .0 to indicate grants. /// /// Note this string list should contain ALL IP addresses to grant /// not just new and added ones (ie. use GetList first and then /// add to the list. /// </summary> /// <param name="IPStrings"></param> public void SetIpList(string[] IPStrings) { this.Open(); object IPSecurity = IIS.Properties["IPSecurity"].Value; // *** IMPORTANT: This list MUST be object or COM call will fail! List <object> newIpList = new List <object>(); foreach (string Ip in IPStrings) { string newIp; if (Ip.EndsWith(".*.*.*") || Ip.EndsWith(".0.0.0")) { newIp = Ip.Replace(".*", ".0") + ",255.0.0.0"; } else if (Ip.EndsWith(".*.*") || Ip.EndsWith(".0.0")) { newIp = Ip.Replace(".*", ".0") + ",255.255.0.0"; } else if (Ip.EndsWith(".*") || Ip.EndsWith(".0")) { // *** Wildcard requires different IP Mask newIp = Ip.Replace(".*", ".0") + ",255.255.255.0"; } else { newIp = Ip + ", 255.255.255.255"; } // *** Check for dupes - nasty but required because // *** object -> string comparison can't do BinarySearch bool found = false; foreach (string tempIp in newIpList) { if (newIp == tempIp) { found = true; break; } } if (!found) { newIpList.Add(newIp); } } //wwUtils.SetPropertyCom(this.IPSecurity, "GrantByDefault", true); IPSecurity.GetType().InvokeMember("GrantByDefault", BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] { true }); object[] ipList = newIpList.ToArray(); IPSecurity.GetType().InvokeMember("GrantByDefault", BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] { false }); // *** Apply the new list //wwUtils.SetPropertyCom(this.IPSecurity, "IPGrant",ipList); IPSecurity.GetType().InvokeMember("IPGrant", BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] { ipList }); IIS.Properties["IPSecurity"].Value = IPSecurity; IIS.CommitChanges(); IIS.RefreshCache(); this.Close(); }