I just finished building version 184.108.40.206 of my FirewallPermission implementation it is a custom permission and associated declaritive security attribute which uses the Windows Firewall COM interfaces to check whether a program has inbound access on a port enabled.
The implementation is pretty basic right now, but if there is an interest in this then I will rev it with some more enumerations for allowing more fine grained definition of the access required. At the moment you use it like this:
[FirewallPermission(SecurityAction.Demand, Port = 1234)]
public void SomeCode()
If the demand fails then you get a SecurityException. It will only run on machines that have Windows XP SP2 installed – maybe this is enough of an incentive for you to get off your butt and test out your applications on it!
There are a few things you need to be aware of. First – the interop library has been hacked – its what VS.NET generates, except it has been disassembled and strongly signed. Second, if you get in there and tweak the code remember that VS.NET runs the C# compiler in-proc so it will always use the old version of the permission to emit the XML into the IL stream. I worked around this by doing the editing in VS.NET but then defering to the command-line to do a build and test.
Hope it works, if you have any questions, problems or feedback just leave some comments on this post or e-mail me at firstname.lastname@example.org.