지정한 아이피 및 포트 번호를 차단하는 프로그램입니다.
좋은목적으로 쓸려면 방화벽을 만들 수 있겠고,
나쁜 목적으로...핑 해킹 등의 목적으로 만들 수 있겠죠?

부디 좋은 목적으로 사용하시길 부탁드립니다.

#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <fltdefs.h>
//#include <Iphlpapi.h>

#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "iphlpapi.lib")
void GetLocalIP(PBYTE szIP);

int main(int argc, char* argv[])
{
    BYTE localIp[4] = {0,};
    BYTE OutIp[] = {115, 68, 57, 2}; //www.devpia.com

    GetLocalIP(localIp);

    INTERFACE_HANDLE hInterface;
    PfCreateInterface(0,
        PF_ACTION_FORWARD,
        PF_ACTION_FORWARD,//PF_ACTION_DROP,
        FALSE,
        TRUE,
        &hInterface);
    
    PfBindInterfaceToIPAddress(hInterface, PF_IPV4, localIp);
   

    FILTER_HANDLE fHandle;

    PF_FILTER_DESCRIPTOR inFilter = {0};
    inFilter.dwFilterFlags = FD_FLAGS_NOSYN;
    inFilter.dwRule = 0;
    inFilter.pfatType = PF_IPV4;
    inFilter.SrcAddr = localIp;
    inFilter.SrcMask = (PBYTE)"\xff\xff\xff\xff";
    inFilter.wSrcPort = FILTER_TCPUDP_PORT_ANY;
    inFilter.wSrcPortHighRange = FILTER_TCPUDP_PORT_ANY;
    inFilter.DstAddr = OutIp;
    inFilter.DstMask = (PBYTE)"\xFF\xFF\xFF\xFF";
    inFilter.wDstPort = FILTER_TCPUDP_PORT_ANY;//FILTER_TCPUDP_PORT_ANY
    inFilter.wDstPortHighRange = FILTER_TCPUDP_PORT_ANY;//FILTER_TCPUDP_PORT_ANY
    inFilter.dwProtocol = FILTER_PROTO_TCP;
    //inFilter.dwProtocol = FILTER_PROTO_ANY;
    inFilter.fLateBound = LB_SRC_ADDR_USE_DSTADDR_FLAG|LB_DST_ADDR_USE_DSTADDR_FLAG;
   
    PfAddFiltersToInterface(hInterface, 0, NULL, 1, &inFilter, &fHandle);
    //PfAddFiltersToInterface(hInterface, 1, &inFilter, 0, NULL, &fHandle);
    //PfAddFiltersToInterface(hInterface, 1, &inFilter, 0, NULL, NULL);

    _getch();

    PfRemoveFilterHandles(hInterface, 1, &fHandle);

    PfUnBindInterface(hInterface);
    PfDeleteInterface(hInterface);

    return 0;
}

void GetLocalIP(PBYTE szIP)
{
    WORD wVersionRequested;
    WSADATA wsaData;
    char name[255];
    char *szIP2 = NULL;
    PHOSTENT hostinfo;
    wVersionRequested = MAKEWORD( 2, 0 );
   
    if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
    {
        if( gethostname ( name, sizeof(name)) == 0)
        {
            if((hostinfo = gethostbyname(name)) != NULL)
            {
                szIP2 = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
            }
        }     
        WSACleanup( );
    }

    char *tmp;
    int i=0;
    for(tmp = strtok(szIP2,"."); tmp!=NULL; tmp=strtok(NULL, "."))
    {
        szIP[i] = atoi(tmp);
        i++;
    }
}

소스가 깔끔하지 못한 느낌이 드네요.
하지만 약간에 도움이라도 될 수 있도록 부끄럽지만 올려봅니다~
Posted by 띠깜
,