Windows 7防火墙书

编程入门 行业动态 更新时间:2024-10-27 02:22:20
本文介绍了Windows 7防火墙书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有谁知道一本解释如何为Windows 7构建防火墙的书? 希望使用Visual Studio2010.2种方法.您可以使用Windows现有的防火墙,对其进行自定义以检查允许的IP地址的在线数据库,也可以编写一个新的做同样的事情.

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.

推荐答案

您可以驱动Windows防火墙使用COM API,即Windows筛选平台上的一层.如果您想直接开发WFP,最好改变主意. WFP是用于构建防火墙的低级API,不能直接从传统应用程序进行管理. 在Visual C ++项目中使用防火墙API的起点是stdafx.h中的以下语句: #import"netfw.tlb" named_namespace("fw") #include< Netfw.h> import语句触发两个文件的创建: netfw.tlh包含诸如类型库(_COM_SMARTPTR_TYPEDEF)中的类型的强类型智能指针,枚举和接口声明之类的内容netfw.tli包含用于包装调用并引发异常以代替HRESULT的方法. named_namespace伪指令是您可以为在这两个文件中创建的所有代码选择C ++名称空间名称的方式,在我们的示例中为"fw".现在,使用COM API非常简单.让我们看看如何列出防火墙规则: typedef BOOL(* RuleCallback)(fw :: INetFwRulePtr& Rule); void ListRules(RuleCallback回调) { HRESULT小时; //连接到防火墙 fw :: INetFwPolicy2Ptr Pol2; hr = Pol2.CreateInstance(__ uuidof(fw :: NetFwPolicy2)); if(Pol2 == NULL) 返回; //检索收集规则 fw :: INetFwRulesPtr Rules = Pol2-> Rules; if(规则== NULL) 返回; //枚举集合并调用回调函数 ULONG num; 变量obj; IEnumVARIANTPtr枚举数=规则-> Get_NewEnum(); while(enumerator-> Next(1,& obj,& num)== S_OK) { fw :: INetFwRulePtr Rule = obj; if(!Callback(Rule)) 返回; } } 再次添加,删除和处理服务规则非常简单. 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.

更多推荐

Windows 7防火墙书

本文发布于:2023-08-06 04:37:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:防火墙   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!