C ++中的Internet使用监控工具

时间:2011-07-08 11:50:56

标签: c++ networking web monitoring traffic

我被告知要编写一个在后台运行的C ++程序,并记录所访问的网站或从计算机上传/下载到互联网的文件。将来,它需要进行扩展,以便程序可以从我办公室局域网中的任何计算机上跟踪互联网使用情况。

该程序将在各种Windows操作系统上运行,从Windows 2000到Windows 7。

有人可以帮助我吗?

3 个答案:

答案 0 :(得分:1)

您需要编写数据包嗅探器。如果你想要一个好的数据包嗅探器,它是非常实用的项目。在网上搜索。了解C / C ++套接字库以开始使用。下面有一些网站。 herehere

答案 1 :(得分:1)

嗯......在公司的Web代理服务器上执行该功能会不会更容易?他们中的大多数甚至都有插件来执行这个功能,因此实际上不需要编写任何代码。

答案 2 :(得分:0)

您可以使用以下代码,其优点是它还可以捕获隐私浏览。

CoInitialize(NULL);

LHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_VALUECHANGE, 0, RT_Browsing_WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);

然后回调函数将是:

void CALLBACK RT_Browsing_WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
    IAccessible* pAcc = NULL;
    VARIANT varChild;
    HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);
    if ((hr == S_OK) && (pAcc != NULL))
    {
        BSTR bstrName, bstrValue;
        pAcc->get_accValue(varChild, &bstrValue);
        pAcc->get_accName(varChild, &bstrName);

        char className[50];
        GetClassNameA(hwnd, className, 50);

        if (bstrName && bstrValue)
        {
            if ((strcmp(className, "Internet Explorer_Server") == 0))
            {
                if (IsValidURL(NULL, bstrValue, NULL) == S_OK)
                {
                    if (bstrValue != E_LastURL)
                    {
                        // bstrValue will hold the new URL (Internet Explorer)
                        E_LastURL = bstrValue;
                    }
                }
            }

            if ((strcmp(className, "Chrome_WidgetWin_1") == 0) && (wcscmp(bstrName, L"Address and search bar") == 0))
            {
                if (IsValidURL(NULL, bstrValue, NULL) == S_OK)
                {
                    if (bstrValue != C_LastURL && bstrValue != L"")
                    {
                        // bstrValue will hold the new URL (Chrome)
                        C_LastURL = bstrValue;
                    }
                }
            }
        }
        pAcc->Release();
    }
}
相关问题