Click here to Skip to main content
13,087,810 members (77,660 online)
Rate this:
Please Sign up or sign in to vote.
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]
Posted 11-Nov-12 1:51am
Updated 11-Nov-12 2:27am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100