Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to determine firewall status of a remote machine?

I used following codes,
   TcpClient tcp = new TcpClient();
    tcp.Connect("RemoteIP", Convert.ToInt16(135));
catch (Exception ex)

Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", REMOTEIP, false);
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
Firewallenabled = mgr.LocalPolicy.CurrentProfile.FirewallEnabled;
return Firewallenabled;

* The first one will always connects to the port 135 if though Firewall is ON/OFF
* The Second one will determine the status correctly but,it requires user to be in the administrator group of remote machines and My Machine is of 64 bit and remote machine is of 32 bit which throws COM ERROR

Any other work around or Suggestions are welcomed,
Plz do reply
thank you in advance


[edit]code blocks added[/edit]
Updated 11-Nov-12 3:27am

1 solution

Unless you use the second code snippet, there is no reliable way for you to determine the status of a remote firewall. It's that way for security reasons.

If you can or cannot connect to a port has no bearing on the status of the firewall on that machine. If you cannot connect to the port, either the firewall is running or the server listening on that port is not listening or not running. There is no way to tell.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900