?? 網絡評估view.cpp
字號:
int querygroup(LPWSTR szServer,LPVOID lParam){
CMyView*pView=(CMyView*)lParam;
HWND hwnd=pView->GetSafeHwnd();
pView->AddString("列舉工作組...要等待一段時間...");
::SendMessage(hwnd,WM_REDRAW,0,0);
UCHAR temp[300],temp1[100];
PNET_DISPLAY_GROUP pBuff, p;
DWORD res, dwRec, i = 0;
do{
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetQueryDisplayInformation_dll=(LPFNDLLFUNC3)GetProcAddress(FLibHandle, "NetQueryDisplayInformation");
if (NetQueryDisplayInformation_dll!=NULL)
{
res = NetQueryDisplayInformation_dll(szServer, 3, i, 1000, 25, &dwRec, (PVOID *)&pBuff);
FreeLibrary(FLibHandle);
}
if((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)){
p = pBuff;
pView->AddString("Group Query Results-----------------");
pView->AddString("Name: Comment: Group ID: Attributes:");
for(;dwRec>0;dwRec--)
{
sprintf((LPTSTR)temp,"%S %S %u %u",
p->grpi3_name,
p->grpi3_comment,
p->grpi3_group_id,
p->grpi3_attributes);
pView->AddString(temp);
sprintf((LPTSTR)temp1,"%S",p->grpi3_name);
pView->m_stringGroups.AddTail(temp1);
::SendMessage(hwnd,WM_REDRAW,0,0);
i = p->grpi3_next_index; //if there is more then set the index
p++;
}
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetApiBufferFree_dll3=(LPFNDLLFUNC8)GetProcAddress(FLibHandle, "NetApiBufferFree");
if (NetApiBufferFree_dll3!=NULL)
{
NetApiBufferFree_dll3(pBuff);
FreeLibrary(FLibHandle);
}
return(0);
}
else{
if((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA))
sprintf((LPTSTR)temp,"Group Enumeration Error:(%u)" ,res);//, ErrorHandle(pParam).begin());
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
return(-1);
}
}while (res==ERROR_MORE_DATA);
}
int querytransport(LPWSTR pszServerName,LPVOID lParam)
{
CMyView*pView=(CMyView*)lParam;
HWND hwnd=pView->GetSafeHwnd();
pView->AddString("列舉netbios transports...要等待一段時間...");
::SendMessage(hwnd,WM_REDRAW,0,0);
UCHAR temp[300];
LPSERVER_TRANSPORT_INFO_0 pBuf = NULL;
LPSERVER_TRANSPORT_INFO_0 pTmpBuf;
DWORD dwLevel = 0; /* 1 */
DWORD dwPrefMaxLen = 256;//-1
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD dwTotalCount = 0;
NET_API_STATUS nStatus;
DWORD i;
//
// Call the NetServerTransportEnum function; specify level 0.
//
// do // begin do
// {
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetServerTransportEnum_dll=(LPFNDLLFUNC2)GetProcAddress(FLibHandle, "NetServerTransportEnum");
if (NetServerTransportEnum_dll!=NULL)
{
nStatus = NetServerTransportEnum_dll(pszServerName,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
FreeLibrary(FLibHandle);
}
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries;
// process access errors.
//
//sprintf((LPTSTR)temp,"%s-transports",pszServerName + 2);
//(dlglocal->m_HistoryEdit).AppendString(temp);
//(dlglocal->m_HistoryEdit).AppendString("Transports:");
for (i = 0; i < dwEntriesRead; i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
pView->AddString( "An access violation has occurred");
::SendMessage(hwnd,WM_REDRAW,0,0);
break;
}
//
// Print the transport protocol name.
//
sprintf((LPTSTR)temp,"Transport:%S", pTmpBuf->svti0_transportname);
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
pView->m_stringTransports.AddTail(temp);
//(dlglocal->m_HistoryEdit).AppendString("Network Address:");
for(i=0;i<wcslen((unsigned short *)pTmpBuf->svti0_networkaddress);i++)
{
if(i % 2 || i == 0)
{
sprintf((LPTSTR)temp,"%c", pTmpBuf->svti0_networkaddress[i]);
//(dlglocal->m_HistoryEdit).AppendString( temp);
}
else
{
sprintf((LPTSTR)temp,":%c", pTmpBuf->svti0_networkaddress[i]);
//(dlglocal->m_HistoryEdit).AppendString(temp);
}
}
sprintf((LPTSTR)temp,"Network Address:%S", pTmpBuf->svti0_networkaddress);
pView->AddString(temp);
pView->m_stringTransports.AddTail(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, indicate a system error.
//
else
{
sprintf((LPTSTR)temp,"A system error has occurred: %d", nStatus);
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
}
//
// Free the allocated buffer.
//
if (pBuf != NULL)
{
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetApiBufferFree_dll4=(LPFNDLLFUNC9)GetProcAddress(FLibHandle, "NetApiBufferFree");
if (NetApiBufferFree_dll4!=NULL)
{
NetApiBufferFree_dll4(pBuf);
FreeLibrary(FLibHandle);
}
pBuf = NULL;
}
//
// Continue to call NetServerTransportEnum while
// there are more entries.
//
// }
// while (nStatus == ERROR_MORE_DATA); // end do
// Check again for an allocated buffer.
//
if (pBuf != NULL)
{
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetApiBufferFree_dll4=(LPFNDLLFUNC9)GetProcAddress(FLibHandle, "NetApiBufferFree");
if (NetApiBufferFree_dll4!=NULL)
{
NetApiBufferFree_dll4(pBuf);
FreeLibrary(FLibHandle);
}
}
//
// Print the final count of transports enumerated.
//
sprintf((LPTSTR)temp, "Total of %d entries enumerate", dwTotalCount);
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
return 0;
}
//datetime
int querytime(LPTSTR pszServerName,LPVOID lParam){
CMyView*pView=(CMyView*)lParam;
HWND hwnd=pView->GetSafeHwnd();
pView->AddString("列舉時間...要等待一段時間...");
::SendMessage(hwnd,WM_REDRAW,0,0);
UCHAR temp[300],temp1[100];
LPTIME_OF_DAY_INFO pBuf = NULL;
NET_API_STATUS nStatus;
DWORD mindiff, hourdiff;
//
// Call the NetRemoteTOD function.
//
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetRemoteTOD_dll=(LPFNDLLFUNC1)GetProcAddress(FLibHandle, "NetRemoteTOD");
if (NetRemoteTOD_dll!=NULL)
{
nStatus = (unsigned long)NetRemoteTOD_dll((LPWSTR)pszServerName,
(LPBYTE *)&pBuf);
FreeLibrary(FLibHandle);
}
else
{
return 1; //出錯
}
//nStatus = NetRemoteTOD(pszServerName,
// (LPBYTE *)&pBuf);
//
// If the function succeeds, display the current date and time.
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
pView->AddString("Date and Time:");
sprintf((LPTSTR)temp,"The current date is: %d/%d/%d", pBuf->tod_month, pBuf->tod_day, pBuf->tod_year);
pView->AddString(temp);
sprintf((LPTSTR)temp1,"%d/%d/%d",pBuf->tod_month, pBuf->tod_day, pBuf->tod_year);
pView->m_stringDateTime.AddTail(temp1);
::SendMessage(hwnd,WM_REDRAW,0,0);
hourdiff = (pBuf->tod_timezone / 60);
mindiff = (pBuf->tod_timezone % 60);
if(pBuf->tod_hours > 12){
sprintf((LPTSTR)temp,"The current time is: %d:%d:%d PM",
pBuf->tod_hours - 12 - hourdiff, pBuf->tod_mins - mindiff, pBuf->tod_secs);
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
} else {
if((pBuf->tod_hours -= hourdiff) == 0)
pBuf->tod_hours = 12;
{
sprintf((LPTSTR)temp,"The current time is: %d:%d:%d AM", pBuf->tod_hours , pBuf->tod_mins - mindiff,
pBuf->tod_secs);
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
}
}
sprintf((LPTSTR)temp1,"%d:%d:%d",pBuf->tod_hours, pBuf->tod_mins, pBuf->tod_secs);
pView->m_stringDateTime.AddTail(temp1);
}
}
//
// Otherwise, display a system error.
else
{
sprintf((LPTSTR)temp,"A system error has occurred: %d", nStatus);
pView->AddString(temp);
::SendMessage(hwnd,WM_REDRAW,0,0);
}
//
// Free the allocated buffer.
//
if (pBuf != NULL)
{
HINSTANCE FLibHandle=LoadLibrary("NETAPI32.DLL");
NetApiBufferFree_dll5=(LPFNDLLFUNC10)GetProcAddress(FLibHandle, "NetApiBufferFree");
if (NetApiBufferFree_dll5!=NULL)
{
NetApiBufferFree_dll5(pBuf);
FreeLibrary(FLibHandle);
}
}
return 0;
}
//services
int queryservices(LPTSTR szServer,LPVOID lParam){
CMyView*pView=(CMyView*)lParam;
HWND hwnd=pView->GetSafeHwnd();
pView->AddString("列舉服務...要等待一段時間...");
::SendMessage(hwnd,WM_REDRAW,0,0);
UCHAR temp[300];
SC_HANDLE scm;
BOOL success;
LPENUM_SERVICE_STATUS status;
DWORD numServices=0, sizeNeeded=0, resume=0;
char *svc = "W3SVC";
// Open a connection to the SCM
scm = OpenSCManager(szServer, 0,
SC_MANAGER_ALL_ACCESS);
if (!scm){
pView->AddString("Error with OpenSCManager");
::SendMessage(hwnd,WM_REDRAW,0,0);
return(-1);
}
// get the number of bytes to allocate
success = EnumServicesStatus(scm,
SERVICE_WIN32 | SERVICE_DRIVER,
SERVICE_ACTIVE | SERVICE_INACTIVE,
0, 0, &sizeNeeded,
&numServices, &resume);
if (GetLastError() != ERROR_MORE_DATA){
pView->AddString("Error with EnumServicesStatus");
::SendMessage(hwnd,WM_REDRAW,0,0);
return(-1);
}
// Allocate space
status = (LPENUM_SERVICE_STATUS)
LocalAlloc(LPTR, sizeNeeded);
// Get the status records. Making an assumption
// here that no new services get added during
// the allocation (could lock the database to
// guarantee that...)
resume = 0;
success = EnumServicesStatus(scm,
SERVICE_WIN32 | SERVICE_DRIVER,
SERVICE_ACTIVE,
status, sizeNeeded, &sizeNeeded,
&numServices,
&resume);
if (!success){
pView->AddString("Error with EnumServicesStatus");
::SendMessage(hwnd,WM_REDRAW,0,0);
return(-1);
}
DWORD i;
pView->AddString("Service Enumeration Results---------------------------");
for (i=0; i < numServices; i++)
{
sprintf((LPTSTR)temp,"%d %s -- %s",i,status[i].lpServiceName,status[i].lpDisplayName);
::SendMessage(hwnd,WM_REDRAW,0,0);
pView->AddString(temp);
pView->m_stringServices.AddTail(temp);
}
// Clean up
LocalFree(status);
CloseServiceHandle(scm);
return(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -