Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anyone know of a books that explain how to build a firewall for Windows 7?
Hopefully using Visual Studio 2010. 2 ways. Either use windows exisiting firewall, customizng it to check an online database for allowed IP address or write a new one doing the same thing.
Posted
Updated 20-Jun-11 3:01am
v3
Comments
Sandeep Mewara 20-Jun-11 2:11am    
You want to make a firewall for Windows7? Or you want to use the existing one. Can you be elaborate on what and why - it might help others answering/referring you to some material.
Member 7766180 20-Jun-11 9:02am    
See updated question. Thank you.

1 solution

You can drive the Windows Firewall using a COM API, a layer over the Windows Filtering Platform. If you are thinking to develop directly the WFP, it's better to change your idea. WFP is a low level API to build Firewalls and not to be managed directly from traditional applications.

The starting point to use the firewall API in a Visual C++ project is the following statements in the stdafx.h:

#import "netfw.tlb" rename_namespace("fw")
#include <Netfw.h>

The import statement trigger the creation of two files:
netfw.tlh contains things like strong typed smartpointers for the types in the type library (_COM_SMARTPTR_TYPEDEF), enums and interface declarations netfw.tli contains methods that wraps calls and throws exceptions in place of HRESULTs. The rename_namespace directive is the way you can choose the C++ namespace name for all the code created in those two files, in our case "fw". Using the COM API is now very simple. Let's see how to list the firewall rules:

typedef BOOL (*RuleCallback)(fw::INetFwRulePtr& Rule);
void ListRules(RuleCallback Callback)
{
HRESULT hr;
// Connect to the firewall
fw::INetFwPolicy2Ptr Pol2;
hr = Pol2.CreateInstance(__uuidof(fw::NetFwPolicy2));
if(Pol2 == NULL)
return;
// Retrieve collection rules
fw::INetFwRulesPtr Rules = Pol2->Rules;
if(Rules == NULL)
return;
// enumerate the collection and call a callback function
ULONG num;
VARIANT obj;
IEnumVARIANTPtr enumerator = Rules->Get_NewEnum();
while(enumerator->Next(1, &obj, &num) == S_OK)
{
fw::INetFwRulePtr Rule = obj;
if(!Callback(Rule))
return;
}
}

Adding, deleting, and working on service rules, is again very simple.
 
Share this answer
 
v3
Comments
Member 7766180 20-Jun-11 9:01am    
Thank you so much. I will ply with this today and get back to you.
Member 7766180 18-Jul-11 13:17pm    
Enrico, I looked at this and I was wondering.... I have an online database that has a list of "ALLOWED" IP's. I want to check this database when a packet comes in, if the IP of the packet is on this database then the packet passes, if not, then the packet is dropped. Can this be done?

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