public FW_ERROR_CODE IsPortEnabled(int nPortNumber, NET_FW_IP_PROTOCOL_ ipProtocol, ref bool bEnable) { if (m_FirewallProfile == null) { return(FW_ERROR_CODE.FW_ERR_INITIALIZED); } // Retrieve the open ports collection INetFwOpenPorts FWOpenPorts = m_FirewallProfile.GloballyOpenPorts; if (FWOpenPorts == null) { return(FW_ERROR_CODE.FW_ERR_GLOBAL_OPEN_PORTS); } // Get the open port try { INetFwOpenPort FWOpenPort = FWOpenPorts.Item(nPortNumber, ipProtocol); if (FWOpenPort != null) { bEnable = FWOpenPort.Enabled; } else { bEnable = false; } } catch (FileNotFoundException) { bEnable = false; } return(FW_ERROR_CODE.FW_NOERROR); }
public bool IsPortEnabled(int port, NET_FW_IP_PROTOCOL_ ipProtocol) { DoDisposeCheck(); DoInitializationCheck(); bool result = false; // Retrieve the open ports collection INetFwOpenPorts firewallOpenPorts = mFirewallProfile.GloballyOpenPorts; if (firewallOpenPorts == null) { throw new FirewallException("Failed to get globally open ports."); } // Get the open port try { INetFwOpenPort firewallOpenPort = firewallOpenPorts.Item(port, ipProtocol); if (firewallOpenPort != null) { result = firewallOpenPort.Enabled; } } catch (Exception) { } return(result); }
public FwErrorCode IsPortEnabled(int nPortNumber, NET_FW_IP_PROTOCOL_ ipProtocol, ref bool bEnable) { if (_mFirewallProfile == null) { return(FwErrorCode.FwErrInitialized); } // Retrieve the open ports collection INetFwOpenPorts fwOpenPorts = _mFirewallProfile.GloballyOpenPorts; if (fwOpenPorts == null) { return(FwErrorCode.FwErrGlobalOpenPorts); } // Get the open port try { INetFwOpenPort fwOpenPort = fwOpenPorts.Item(nPortNumber, ipProtocol); bEnable = fwOpenPort?.Enabled == true; } catch (System.IO.FileNotFoundException) { bEnable = false; } return(FwErrorCode.FwNoerror); }