Click here to Skip to main content
11,790,385 members (37,821 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
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
Edited 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
0 OriginalGriff 1,029
1 Maciej Los 790
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 460

Advertise | Privacy | Mobile
Web03 | 2.8.1509028.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2015
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