/ *
Use the API provided by the operating system to write a firewall.
This program involves an API description, please visit Microsoft's MSDN Library
Code compiled in C Builder 5
If you want to exchange with me, please email: zzwinner@163.com
* /
#pragma HDRSTOP
#include "windows.h"
#include "fldedefs.h"
/ / Need to load "iPhlPapi.lib"
#pragma argsused
Int main (int Argc, char * argv [])
{
// A creation of a network package filter interface
Interface_handle hinterface;
PfcreateInterface (0,
PF_Action_DROP, // PF_Action_forward,
PF_Action_DROP, // PF_Action_forward,
False,
True,
& hinterface);
// Bind the IP address that needs the network package filter
BYTE localip [] = {192, 168, 0, 2};
PfbindInterfaceToipadDress (Hinterface, PF_IPv4, localip);
// Now we start filating the interface of the HTTP protocol
Filter_handle fhandle;
// Filled the rule structure of the filter package
PF_FILTER_DESCRIPTOR INFILTER;
Infilter.dwfilterflags = fd_flags_nosyn; // Contains this value
Infilter.dwrule = 0; // Contain this value
Infilter.pfattype = PF_IPv4; // with 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; // Arbitrary Source Port
Infilter.wsrcporthighRange = filter_tcpudp_port_any;
Infilter.dstaddr = 0; // Arbitrary target address
INFILTER.DSTMASK = 0;
Infilter.wdstport = 80; // Target Port 80 (HTTP Service)
Infilter.wdstporthighRange = 80;
Infilter.dwprotocol = filter_proto_tcp; // Filtering protocol
/ / Add a filter interface
PfaddfiltersTointerface (Hinterface, 1, & Infilter, 0, null, & fhandle);
/ / Please set up a trial breakpoint here, then look at whether your IE cannot access the web page. :)
// remove the filter interface
PfremovefilterHandles (Hinterface, 1, & fhandle);
PfunbindInterface (Hinterface);
PfdeeeteInterface (Hinterface);
Return 0;
}