internet usage monitoring tool in C++ [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this questionI have been told to write a C++ program which runs in the background and keeps a log of websites visited or files uploaded/downloaded to internet from the computer. In future, it will need to scaled so that the program can track internet usage from any computer in the LAN of my office.
The program will run on various Windows operating systems, from Windows 2000 to Windows 7.
Can somebody help me in this?
You are required to write a packet sniffer. It's quite hands on project if you want a good packet sniffer written. Do a search on the net. Learn about C/C++ socket library to get started. Some website below. here and here
Um...wouldn't it be far easier to perform that function on the company's web proxy server? Most of them even have plugins to perform this exact function, so no code would actually need to be written.
You can use the following code and the advantage is that it will also capture private browsing.
CoInitialize(NULL);
LHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_VALUECHANGE, 0, RT_Browsing_WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
Then the callback function will be:
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();
}
}
精彩评论