Pregunta

I have written a Windows service that I am needing to port over to Mono so it can be used on Mac / Linux platforms.

It makes use of the FirewallAPI.dll (I think that is the actual name...). The other names are NetFwTypeLb, NATUPNPLib and NETCONLib.

I have been Googling, trying to find a way to implement this on Mac / Linux platforms but I cannot find what I could use to do this.

Is this possible? And combining another question with this one: do Mac / Linux platforms allow services (I think otherwise called 'daemons') to be installed and ran easily?

Thanks, Madeline

Just for note, this is the current code I am using, I got it off of another StackOverflow question:

public class Firewall
{
    public static INetFwMgr WinFirewallManager()
    {
        Type type = Type.GetTypeFromCLSID(
            new Guid("{304CE942-6E39-40D8-943A-B913C40C9CD4}"));
        return Activator.CreateInstance(type) as INetFwMgr;
    }
    public bool AuthorizeProgram(string title, string path,
        NET_FW_SCOPE_ scope, NET_FW_IP_VERSION_ ipver)
    {
        Type type = Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication");
        INetFwAuthorizedApplication authapp = Activator.CreateInstance(type)
            as INetFwAuthorizedApplication;

        authapp.Name = title;
        authapp.ProcessImageFileName = path;
        authapp.Scope = scope;
        authapp.IpVersion = ipver;
        authapp.Enabled = true;

        EventLog.WriteEntry("MachineVerification", authapp.Name + " " + authapp.Scope + " " + authapp.IpVersion);

        INetFwMgr mgr = WinFirewallManager();
        try
        {
            mgr.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(authapp);

            EventLog.WriteEntry("MachineVerification", authapp.Name + " " + authapp.Scope + " " + authapp.IpVersion);
        }
        catch (Exception ex)
        {
            EventLog.WriteEntry("MachineVerification", "MROW!" + ex.Message);
            return false;
        }
        return true;
    }
}
¿Fue útil?

Solución

I forgot to answer this when I figured it all out!

On OS X, there is no need for making a firewall exception. OS X will ask the user to give your application permission to access the internet.

I am not sure about Linux though, but Mono coverage is a lot higher on Linux so I am sure someone has answered this question for Linux before.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top