IP package filter

xiaoxiao2021-03-06  26

IP package filter

2004-05-27 zzwinner / * Using the API provided by the operating system to write a firewall. The API description involved, please visit Microsoft's MSDN Library code 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 argsusedint main (int Argc, char * argv []) {// a creation network package filtering interfaces INTERFACE_HANDLE hInterface; PfCreateInterface (0, PF_ACTION_DROP, // PF_ACTION_FORWARD, PF_ACTION_DROP, // PF_ACTION_FORWARD, FALSE, TRUE, & hInterface); // bind the network packet filtering requires IP address BYTE localIp [] = {192,168,0,2 }; PfBindInterfaceToIPAddress (hInterface, PF_IPV4, localIp); // now we begin filtering HTTP protocol interface FILTER_HANDLE fHandle; // filled filter bag regular structure PF_FILTER_DESCRIPTOR inFilter; inFilter.dwFilterFlags = FD_FLAGS_NOSYN; // this value has been added inFilter. DWRULE = 0; // Contains this value INFILTER.PFATTYPE = PF_IPv4; // Use IPv4 Address INFILTER.SRCADDR = localip; // Set local IP address infilter.srcmask = "/ xff / XFF / XFF / XFF"; // set the local subnet mask inFilter.wSrcPort = FILTER_TCPUDP_PORT_ANY; // any source port inFilter.wSrcPortHighRange = FILTER_TCPUDP_PORT_ANY; inFilter.DstAddr = 0; // arbitrary target address inFilter.DstMask = 0; inFilter.wDstPort = 80; // Destination port 80 (HTTP Service) Infilte R.WDStportHighRange = 80; Infilter.dwprotocol = filter_proto_tcp; // Filter Protocol // Add a filter interface PfaddfiltersTointerface (Hinterface, 1, & Infilter, 0, null, & fhandle); // Please set up a debug point, then Look at whether your IE cannot access the web page.:) // remove the filter interface PfremoveFilterHandles (Hinterface, 1, & fhandle); pfunbindinterface; pfdeleteinterface; return 0;}

转载请注明原文地址:https://www.9cbs.com/read-58868.html

New Post(0)