/*
Use the API provided by the operating system to write firewalls.
The program involves API instructions please visit Microsoft's MSDN Library
Code is compiled in C + + Builder 5 through
If you want to communicate with me, please email:zzwinner@163.com.
*/
#pragma hdrstop
#include "Windows.h"
#include "Fltdefs.h"
Need to load "iphlpapi.lib"
//---------------------------------------------------------------------------
#pragma argsused
int main (int argc, char* argv[])
{
A Create network packet filter interface
Interface_handle Hinterface;
Pfcreateinterface (0,
Pf_action_drop,//pf_action_forward,
Pf_action_drop,//pf_action_forward,
FALSE,
TRUE,
&hinterface);
Bindings require IP addresses for network packet filtering
BYTE localip[] = {192,168,0,2};
Pfbindinterfacetoipaddress (Hinterface, Pf_ipv4, Localip);
Now let's start filtering the interfaces of the HTTP protocol
Filter_handle Fhandle;
Rule structure for filling filter packs
Pf_filter_descriptor Infilter;
Infilter.dwfilterflags = Fd_flags_nosyn; Always add this value
Infilter.dwrule = 0; Always add this value
Infilter.pfattype = Pf_ipv4; Use ipV4 Address
INFILTER.SRCADDR = Localip; Set Local IP Address
Infilter.srcmask = "\xff\xff\xff\xff"; Set Local subnet mask
Infilter.wsrcport = Filter_tcpudp_port_any; Any source port
Infilter.wsrcporthighrange = Filter_tcpudp_port_any;
infilter.dstaddr = 0; Any destination address
Infilter.dstmask = 0;
Infilter.wdstport = 80; Destination port (HTTP service)
Infilter.wdstporthighrange = 80;
Infilter.dwprotocol = filter_proto_tcp; Filtered Protocols
Add a filter interface
Pfaddfilterstointerface (Hinterface, 1, &infilter, 0, NULL, &fhandle);
Set a debug breakpoint here and see if your IE doesn't have access to the Web page. :)
Remove Filter Interface
Pfremovefilterhandles (Hinterface, 1, &fhandle);
Pfunbindinterface (Hinterface);
Pfdeleteinterface (Hinterface);
return 0;
}