001
12.09.2006, 12:37 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, aus 'nem "alten" Projekt:
C++: |
#include <winsock2.h> #pragma comment (lib,"ws2_32.lib") #pragma comment (lib,"mpr.lib")
void CIPDlg::OnBnClickedButton1() { CString strTemp; struct hostent *host; struct in_addr *ptr;
DWORD dwScope = RESOURCE_CONTEXT; NETRESOURCE *NetResource = NULL; HANDLE hEnum; WNetOpenEnum( dwScope, NULL, NULL, NULL, &hEnum );
WSADATA wsaData; WSAStartup(MAKEWORD(1,1),&wsaData);
if ( hEnum ) { DWORD Count = 0xFFFFFFFF; DWORD BufferSize = 2048; LPVOID Buffer = new char[2048]; WNetEnumResource( hEnum, &Count, Buffer, &BufferSize ); NetResource = (NETRESOURCE*)Buffer;
char szHostName[200];
for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ ) { if ( NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY ) { if ( NetResource->lpRemoteName ) { CString strFullName = NetResource->lpRemoteName; if ( 0 == strFullName.Left(2).Compare("\\\\") ) strFullName = strFullName.Right(strFullName.GetLength()-2); gethostname( szHostName, strlen( szHostName ) ); host = gethostbyname(strFullName); if(host == NULL) continue; ptr = (struct in_addr *) host->h_addr_list[0];
int a = ptr->S_un.S_un_b.s_b1; int b = ptr->S_un.S_un_b.s_b2; int c = ptr->S_un.S_un_b.s_b3; int d = ptr->S_un.S_un_b.s_b4;
strTemp.Format("%s --> %d.%d.%d.%d",strFullName,a,b,c,d); AfxMessageBox(strTemp); } } } delete Buffer; WNetCloseEnum( hEnum ); } WSACleanup(); }
|
Paar Anpassungen an Deine Bedürfnisse müssen wohl noch gemacht werden -- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 12.09.2006 um 12:40 Uhr von Uwe editiert. |