private static bool AddWindowsFirewallEntry(string appPath) { switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: if (Environment.OSVersion.Version.Major > 5) { //vista and above try { RuleStatus status = WindowsFirewall.RuleExistsVista("", appPath); switch (status) { case RuleStatus.Blocked: case RuleStatus.Disabled: WindowsFirewall.RemoveRuleVista("", appPath); break; case RuleStatus.Allowed: return(true); } WindowsFirewall.AddRuleVista("Technitium DNS Server", "Allow incoming connection request to the DNS server.", FirewallAction.Allow, appPath, Protocol.ANY, null, null, null, null, InterfaceTypeFlags.All, true, Direction.Inbound, true); return(true); } catch { } } else { try { RuleStatus status = WindowsFirewall.ApplicationExists(appPath); switch (status) { case RuleStatus.Disabled: WindowsFirewall.RemoveApplication(appPath); break; case RuleStatus.Allowed: return(true); } WindowsFirewall.AddApplication("Technitium DNS Server", appPath); return(true); } catch { } } break; } return(false); }
private static void AddWindowsFirewallEntry(string appPath) { switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: if (Environment.OSVersion.Version.Major > 5) { //vista and above try { RuleStatus status = WindowsFirewall.RuleExistsVista("", appPath); switch (status) { case RuleStatus.Blocked: case RuleStatus.Disabled: WindowsFirewall.RemoveRuleVista("", appPath); break; case RuleStatus.Allowed: return; } WindowsFirewall.AddRuleVista("Bit Chat", "Allow incoming connection request to Bit Chat application.", FirewallAction.Allow, appPath, Protocol.ANY); } catch { } } else { try { RuleStatus status = WindowsFirewall.ApplicationExists(appPath); switch (status) { case RuleStatus.Disabled: WindowsFirewall.RemoveApplication(appPath); break; case RuleStatus.Allowed: return; } WindowsFirewall.AddApplication("Bit Chat", appPath); } catch { } } break; } }
private bool AddWindowsFirewallEntry(string appPath) { try { RuleStatus status = WindowsFirewall.RuleExistsVista("", appPath); switch (status) { case RuleStatus.Blocked: case RuleStatus.Disabled: WindowsFirewall.RemoveRuleVista("", appPath); break; case RuleStatus.Allowed: return(true); } WindowsFirewall.AddRuleVista("Technitium DNS Server", "Allows incoming connection request to the DNS server.", FirewallAction.Allow, appPath, Protocol.ANY, null, null, null, null, InterfaceTypeFlags.All, true, Direction.Inbound, true); //add web console rule try { WindowsFirewall.RemoveRuleVista("Technitium DNS Server Web Console", ""); } catch { } try { WindowsFirewall.AddRuleVista("Technitium DNS Server Web Console", "Allows access to the DNS server web console.", FirewallAction.Allow, null, Protocol.TCP, _service.WebServiceHttpPort + ", " + _service.WebServiceTlsPort, null, null, null, InterfaceTypeFlags.All, true, Direction.Inbound, true); } catch { } return(true); } catch { return(false); } }
private void AddWindowsFirewallEntry() { if (Environment.OSVersion.Version.Major < 6) { //below vista try { if (!WindowsFirewall.PortExists(Protocol.TCP, _service.ExternalSelfEP.Port)) { WindowsFirewall.AddPort("Bit Chat - TCP", Protocol.TCP, _service.ExternalSelfEP.Port, true); } if (!WindowsFirewall.PortExists(Protocol.UDP, 41733)) { WindowsFirewall.AddPort("Bit Chat - Local Discovery", Protocol.UDP, 41733, true); } } catch { } } else { //vista & above try { string appPath = Assembly.GetEntryAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\"); if (!WindowsFirewall.RuleExistsVista("Bit Chat", appPath)) { WindowsFirewall.AddRuleVista("Bit Chat", "Allow incoming connection request to Bit Chat application.", FirewallAction.Allow, appPath, Protocol.ANY); } } catch { } } }