/// <summary> /// インバウンド TCP 許可しているポートとプロファイルを一覧で出力します /// </summary> /// <remarks> /// <list type="bullet"> /// <item>domain,allow,tcp,12345</item> /// <item>private,allow,tcp,12345</item> /// <item>public,allow,tcp,12345</item> /// </list> /// </remarks> /// <returns></returns> public string[] EnumAllAllowed() { List <string> al = new List <string>(); IEnumerator fwRulesEnum = (IEnumerator)fwRules.GetType().InvokeMember("_NewEnum", System.Reflection.BindingFlags.GetProperty, null, fwRules, new Object[0]); while (fwRulesEnum.MoveNext()) { INetFwRule fwRule = (INetFwRule)fwRulesEnum.Current; try { if (true && fwRule.Direction == NET_FW_RULE_DIRECTION.IN && fwRule.Enabled && fwRule.Protocol == 6 && string.IsNullOrEmpty(fwRule.ApplicationName) ) { bool allow = fwRule.Action == NET_FW_ACTION.ALLOW; BitArray ports = Ut.GetPorts(fwRule.LocalPorts ?? ""); NET_FW_PROFILE_TYPE2 profs = fwRule.Profiles; for (int x = 0; x < 65536; x++) { if (ports[x]) { if (0 != (profs & NET_FW_PROFILE_TYPE2.DOMAIN)) { al.Add("domain,allow,tcp," + x + ""); } if (0 != (profs & NET_FW_PROFILE_TYPE2.PRIVATE)) { al.Add("private,allow,tcp," + x + ""); } if (0 != (profs & NET_FW_PROFILE_TYPE2.PUBLIC)) { al.Add("public,allow,tcp," + x + ""); } } } } } finally { Marshal.ReleaseComObject(fwRule); } } return(al.ToArray()); }
public void AllowTCP(int port, NET_FW_PROFILE_TYPE2 profile) { MarshalByRefObject fwRule = (MarshalByRefObject)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule")); try { INetFwRule newRule = (INetFwRule)fwRule; newRule.Name = string.Format("TCP {0}", port); newRule.Description = "IsFwAllowed"; newRule.Protocol = 6; newRule.LocalPorts = "" + port; newRule.Direction = NET_FW_RULE_DIRECTION.IN; newRule.Enabled = true; newRule.Profiles = profile; newRule.Action = NET_FW_ACTION.ALLOW; fwRules.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, fwRules, new Object[] { fwRule }); } finally { Marshal.ReleaseComObject(fwRule); } }
internal FirewallProfile(INetFwPolicy2 underlyingObject, NET_FW_PROFILE_TYPE2 profile) { _profile = profile; UnderlyingObject = underlyingObject; }
internal FirewallWASProfile(FirewallWAS firewall, NET_FW_PROFILE_TYPE2 profileType) { _profileType = profileType; _firewall = firewall; }