views:

198

answers:

1

Given - .Net 2.0 XP machine with SP2 and multiple network adapters

Is there an API that can be used to check if the network adapter is firewalled?

OneGuyInDC

+2  A: 

It is not possible to know in general (e.g. if there is an external firewall) for the following reasons:

  1. If you aren't receiving incoming connections, your external interface may just be down.
  2. If you are unable to make outgoing connections, your external interface may just be down.

But there is an API for finding out if the Windows Firewall is enabled on a given network interface. You will need to use COM interop to get the INetFwProfile (for global firewall status) and INetSharingConfiguration (for a specific network interface) interfaces, and check INetFwProfile.FirewallEnabled and INetSharingConfiguration.InternetFirewallEnabled.

See http://msdn.microsoft.com/en-us/library/aa364717%28VS.85%29.aspx for links and for how to use these results to determine the effective firewall status. (It's written in terms of VBScript but should be translatable to C#.)

itowlson
Merged Answers and +1
John Gietzen