⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isapiip.cpp

📁 INTERNET网络高级编程的包括邮件加密、MAPI、ISAPI、ACTIVEX、FTP等等。
💻 CPP
字号:
// ISAPIIP.CPP - Implementation file for your Internet Server
//    IsapiIP Filter

#include "stdafx.h"
#include "IsapiIP.h"

///////////////////////////////////////////////////////////////////////
// The one and only CWinApp object
// NOTE: You may remove this object if you alter your project to no
// longer use MFC in a DLL.

CWinApp theApp;



///////////////////////////////////////////////////////////////////////
// The one and only CIsapiIPFilter object

CIsapiIPFilter theFilter;


///////////////////////////////////////////////////////////////////////
// CIsapiIPFilter implementation

CIsapiIPFilter::CIsapiIPFilter()
{
	str[1]="202.104.7.*";
    str[2]="202.112.*.*";
	str[3]="203.*.*.*";
	//szAddressList1[80]="202.104.7.*";
	//szAddressList2[80]="202.112.*.*";
	//szAddressList3[80]="202.5.*.*";
}

CIsapiIPFilter::~CIsapiIPFilter()
{
}

BOOL CIsapiIPFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
	// Call default implementation for initialization
	CHttpFilter::GetFilterVersion(pVer);

	// Clear the flags set by base class
	pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;

	// Set the flags we are interested in
	pVer->dwFlags |= SF_NOTIFY_ORDER_LOW | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT
			 | SF_NOTIFY_READ_RAW_DATA;

	// Load description string
	TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
	ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
			IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
	_tcscpy(pVer->lpszFilterDesc, sz);
	return TRUE;
}

DWORD CIsapiIPFilter::OnReadRawData(CHttpFilterContext* pCtxt,
	PHTTP_FILTER_RAW_DATA pRawData)
{
	// TODO: React to this notification accordingly and
	// return the appropriate status code
    char szAddress[80];
	DWORD dwSize = sizeof(szAddress);
	if (pCtxt->GetServerVariable("REMOTE_ADDR", szAddress, &dwSize))
	{
		//  Make sure this address is a valid address
		CString strAddress;
		strAddress.Format("%s",szAddress);
		if (strAddress.Left(10)==str[1]||strAddress.Left(8)==str[2]||strAddress.Left(4)==str[3])
		{
			char szResult[80];
			sprintf(szResult,"对不起,您无权访问此页面。");
			unsigned long  len=sizeof(szResult);
			pCtxt->WriteClient(szResult,&len,0);
		}
		else
		{
		    char szResult[80];
			sprintf(szResult,"欢迎访问我的主页。");
			unsigned long  len=sizeof(szResult);
			pCtxt->WriteClient(szResult,&len,0);
		}

		
	}



	return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CIsapiIPFilter, CHttpFilter)
	//{{AFX_MSG_MAP(CIsapiIPFilter)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

///////////////////////////////////////////////////////////////////////
// If your extension will not use MFC, you'll need this code to make
// sure the extension objects can find the resource handle for the
// module.  If you convert your extension to not be dependent on MFC,
// remove the comments arounn the following AfxGetResourceHandle()
// and DllMain() functions, as well as the g_hInstance global.

/****

static HINSTANCE g_hInstance;

HINSTANCE AFXISAPI AfxGetResourceHandle()
{
	return g_hInstance;
}

BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
					LPVOID lpReserved)
{
	if (ulReason == DLL_PROCESS_ATTACH)
	{
		g_hInstance = hInst;
	}

	return TRUE;
}

****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -