操作API编写防火墙
/*
操作操纵系统提供的API编写防火墙.
该措施涉及到的API说明请会见微软的MSDN Library
代码在C++ Builder 5编译通过
假如您想和我交换请email:[email protected]
*/
#pragma hdrstop
#include "windows.h"
#include "Fltdefs.h"
// 需要加载"iphlpapi.lib"
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
// 一个建设网络包过滤接口
INTERFACE_HANDLE hInterface;
PfCreateInterface(0,
PF_ACTION_DROP,//PF_ACTION_FORWARD,
PF_ACTION_DROP,//PF_ACTION_FORWARD,
FALSE,
TRUE,
&hInterface);
// 绑定需要网络包过滤的IP地点
BYTE localIp[] = {192,168,0,2};
PfBindInterfaceToIPAddress(hInterface, PF_IPV4, localIp);
// 此刻我们开始过滤HTTP协议的的接口
FILTER_HANDLE fHandle;
// 填充过滤包的法则布局
PF_FILTER_DESCRIPTOR inFilter;
inFilter.dwFilterFlags = FD_FLAGS_NOSYN; //一直添这个值
inFilter.dwRule = 0; //一直添这个值
inFilter.pfatType = PF_IPV4; //用 ipV4 地点
inFilter.SrcAddr = localIp; //配置当地IP地点
inFilter.SrcMask = "\xff\xff\xff\xff"; //配置当地子网掩码
inFilter.wSrcPort = FILTER_TCPUDP_PORT_ANY; //任意来历端口
inFilter.wSrcPortHighRange = FILTER_TCPUDP_PORT_ANY;
inFilter.DstAddr = 0; //任意方针地点
inFilter.DstMask = 0;
inFilter.wDstPort = 80; //方针端口 80(http 处事)
inFilter.wDstPortHighRange = 80;
inFilter.dwProtocol = FILTER_PROTO_TCP; // 过滤的协议
// 插手一个过滤接口
PfAddFiltersToInterface(hInterface, 1, &inFilter, 0, NULL, &fHandle);
// 请在这配置一个调试断点,然后看看你的IE是否不能会见WEB页. :)
// 移除过滤接口
PfRemoveFilterHandles(hInterface, 1, &fHandle);
PfUnBindInterface(hInterface);
PfDeleteInterface(hInterface);
return 0;
}