用在 ENUM 方面开发经验的朋友,或者 正在研究的 朋友吗?

njuhuangmy 2003-09-29 09:23:34
想 获得 一些 , 能够 获得 的 文档

网上的, 我可以自己 搜索,

希望 一些 比较 详细的, 并不需要 那种 属于 技术秘密的,呵呵

不知道 哪位 可以 帮帮 忙?

3x 先
...全文
67 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyhgg 2003-09-30
  • 打赏
  • 举报
回复
ENUM是个什么东??
njuhuangmy 2003-09-30
  • 打赏
  • 举报
回复
数字域名 系统或者说 技术

zihan 2003-09-29
  • 打赏
  • 举报
回复
你可以找到当前网络中的一些共享文档.给你一点代码
#include <windows.h>
#include <stdio.h>
#include <lm.h>

int DispServer(TCHAR *pszServerName)
{
DWORD dwLevel = 101;
LPSERVER_INFO_101 pBuf = NULL;
NET_API_STATUS nStatus;

//
// Call the NetServerGetInfo function, specifying level 101.
//
nStatus = NetServerGetInfo(pszServerName,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call succeeds,
//
if (nStatus == NERR_Success)
{
//
// Check for the type of server.
//
if ((pBuf->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
(pBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) ||
(pBuf->sv101_type & SV_TYPE_SERVER_NT))
printf("Type: Server\n");
else
printf("Type: Workstation\n");
printf("Name: %S\n",pBuf->sv101_name);
printf("OS: ");
switch(pBuf->sv101_platform_id)
{
case PLATFORM_ID_DOS:
printf("DOS\n");
break;
case PLATFORM_ID_OS2:
printf("OS2\n");
break;
case PLATFORM_ID_NT:
printf("NT\n");
break;
case PLATFORM_ID_OSF:
printf("OSF\n");
break;
case PLATFORM_ID_VMS:
printf("VMS\n");
break;
default:
printf("Unknown\n");
break;
}
printf("Version: %d.%d\n",pBuf->sv101_version_major,pBuf->sv101_version_minor);
printf("Comment: %S\n",pBuf->sv101_comment);
}
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);

return 0;
}
void EnumShare(TCHAR *lpszServer)
{
PSHARE_INFO_1 BufPtr,p;
NET_API_STATUS res;
DWORD er=0,tr=0,resume=0, i;
//
// Print a report header.
//
printf("Share Share Type: \n");
printf("--------------------------------------------------\n");
//
// Call the NetShareEnum function; specify level 1.
//
do // begin do
{
res = NetShareEnum (lpszServer, 1, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
//
// If the call succeeds,
//
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
{
p=BufPtr;
//
// Loop through the entries;
// print retrieved data.
//
for(i=1;i<=er;i++)
{
printf("%-20S",p->shi1_netname);
switch(p->shi1_type)
{
case STYPE_DISKTREE:
printf("%-30s\n","Disk driver");
break;
case STYPE_PRINTQ:
printf("%-30s\n","Printe queue");
break;
case STYPE_DEVICE:
printf("%-30s\n","Communication device");
break;
case STYPE_IPC:
printf("%-30s\n","Interprocess communication (IPC)");
break;
case STYPE_SPECIAL:
printf("%-30s\n","Special share");
break;
default:
printf("%-30s\n","Unknown share");
break;
}

p++;
}
//
// Free the allocated buffer.
//
NetApiBufferFree(BufPtr);
}
else
{
printf("Error: %ld----",res);
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
res,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
//MessageBox( NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONINFORMATION );
printf("%S",(LPCTSTR)lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}
// Continue to call NetShareEnum while
// there are more entries.
//
}while (res==ERROR_MORE_DATA); // end do
return;
}

void DisplayStruct(LPNETRESOURCE lpnr)
{
switch(lpnr->dwDisplayType)
{
case RESOURCEDISPLAYTYPE_DOMAIN:
printf("--------Domain--%S--------\n",lpnr->lpRemoteName);
break;
case RESOURCEDISPLAYTYPE_SERVER:
printf("--------Server--%S--------\n",lpnr->lpRemoteName);
DispServer(lpnr->lpRemoteName);
EnumShare(lpnr->lpRemoteName);
printf("\n\n");
break;
case RESOURCEDISPLAYTYPE_SHARE:
// printf("Share:%S\n",lpnr->lpRemoteName);
break;
default:
// printf("Unknown:%S\n",lpnr->lpRemoteName);
break;
}
}

BOOL WINAPI EnumerateFunc(LPNETRESOURCE lpnr)
{
DWORD dwResult, dwResultEnum;
HANDLE hEnum;
DWORD cbBuffer = 16384; // 16K is a good size
DWORD cEntries = -1; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i;
//
// Call the WNetOpenEnum function to begin the enumeration.
//
dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, // all network resources
RESOURCETYPE_ANY, // all resources
0, // enumerate all resources
lpnr, // NULL first time the function is called
&hEnum); // handle to the resource

if (dwResult != NO_ERROR)
{
return FALSE;
}
//
// Call the GlobalAlloc function to allocate resources.
//
lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);

do
{
//
// Initialize the buffer.
//
ZeroMemory(lpnrLocal, cbBuffer);
//
// Call the WNetEnumResource function to continue
// the enumeration.
//
dwResultEnum = WNetEnumResource(hEnum, // resource handle
¢ries, // defined locally as -1
lpnrLocal, // LPNETRESOURCE
&cbBuffer); // buffer size
//
// If the call succeeds, loop through the structures.
//
if (dwResultEnum == NO_ERROR)
{
for(i = 0; i < cEntries; i++)
{
// Call an application-defined function to
// display the contents of the NETRESOURCE structures.
//
DisplayStruct(&lpnrLocal[i]);

// If the NETRESOURCE structure represents a container resource,
// call the EnumerateFunc function recursively.

if(RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER))
EnumerateFunc(&lpnrLocal[i]);
}
}
// Process errors.
//
else if (dwResultEnum != ERROR_NO_MORE_ITEMS)
{
break;
}
}while(dwResultEnum != ERROR_NO_MORE_ITEMS);
//
// Call the GlobalFree function to free the memory.
//
GlobalFree((HGLOBAL)lpnrLocal);
//
// Call WNetCloseEnum to end the enumeration.
//
dwResult = WNetCloseEnum(hEnum);

if(dwResult != NO_ERROR)
{
return FALSE;
}

return TRUE;
}

int wmain()
{
EnumerateFunc(NULL);
}

4,356

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧