if (argc > 2) { fwprintf(stderr, L "Usage: %s [\\\\ServerName]\n ", argv[0]); exit(1); } // The server is not the default local computer. // if (argc == 2) pszServerName = argv[1]; // // Call the NetServerEnum function to retrieve information // for all servers, specifying information level 101. // nStatus = NetServerEnum(pszServerName, dwLevel, (LPBYTE *) &pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, dwServerType, NULL, &dwResumeHandle); // // If the call succeeds, // if ((nStatus == NERR_Success) ¦ ¦ (nStatus == ERROR_MORE_DATA)) { if ((pTmpBuf = pBuf) != NULL) { // // Loop through the entries and // print the data for all server types. // for (i = 0; i < dwEntriesRead; i++) { assert(pTmpBuf != NULL);
if (pTmpBuf == NULL) { fprintf(stderr, "An access violation has occurred\n "); break; }
printf( "\tPlatform: %d\n ", pTmpBuf- >sv101_platform_id); wprintf(L "\tName: %s\n ", pTmpBuf- >sv101_name); printf( "\tVersion: %d.%d\n ", pTmpBuf- >sv101_version_major, pTmpBuf- >sv101_version_minor); printf( "\tType: %d ", pTmpBuf- >sv101_type); // // Check to see if the server is a domain controller; // if so, identify it as a PDC or a BDC. // if (pTmpBuf- >sv101_type & SV_TYPE_DOMAIN_CTRL) wprintf(L " (PDC) "); else if (pTmpBuf- >sv101_type & SV_TYPE_DOMAIN_BAKCTRL) wprintf(L " (BDC) ");
printf( "\n "); // // Also print the comment associated with the server. // wprintf(L "\tComment: %s\n\n ", pTmpBuf- >sv101_comment);
pTmpBuf++; dwTotalCount++; } // Display a warning if all available entries were // not enumerated, print the number actually // enumerated, and the total number available.
#include "..."
#include "iphlpapi.h"#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )void main( int argc, char ** argv )
{
int numberOfHost = 1;
struct hostent *remoteHostent; //处理命令行参数
if ( argc == 3 )
numberOfHost = atoi( argv[2] );
if ( ( argc >3 ) || ( argc < 2 ) )
{
printf( "RmtHost v0.2 - Get remote HostName /MacAddress\n" );
printf( "by ShotgunLabs ( [email protected] )\n\n" );
printf( "Usage :\n\tRmtHost.exe [RemoteIP] \n\n" );
printf( "Example:\n\tRmtHost.exe 192.168.0.3\n" );
printf( "\tRmtHost.exe 192.168.0.3 255\n\n" );
exit( 0 );
} //初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d\n", GetLastError() );
exit( 0 );
}
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa;
for ( int i = 0; i < numberOfHost; i ++ )
{
//获取远程机器名
sa.s_addr = nRemoteAddr;
printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
if ( remoteHostent )
printf( "HostName : %s\n",remoteHostent->h_name );
else
printf( "gethostbyaddr Error:%d\n",GetLastError() );
//发送ARP查询包获得远程MAC地址 unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet=SendARP(nRemoteAddr, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen);
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i<6; i++ )
{
printf( "%.2x", macAddress[i] );
if ( i<5 ) printf( "-" );
}
printf( "\n" );
}
else
printf( "SendARP Error:%d\n", GetLastError());
nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 );
}
}
回复人:wuxuan(真心英雄) () 信誉:105 2002-9-25 12:23:32 得分: 10 删除
http://www.codeproject.com/internet/ipaddress.asp
http://www.codeproject.com/internet/ipenum.asp
回复人:wuxuan(真心英雄) () 信誉:105 2002-9-25 12:26:55 得分: 10 删除
http://www.codeguru.com/network/network_enum.shtml
http://www.codeguru.com/network/network_enum2.shtml
http://www.codeguru.com/network/network_enum3.shtml
回复人:jennyvenus(北大教授刘伟说堵车是一个城市繁荣的标志) () 信誉:135 2002-9-25 12:32:47 得分: 5 删除
我想这个程序可以运行在服务器上,截获arp包,调用系统函数得到其他信息
也可以运行在连接到服务器的hub上。
回复人:qrlvls(怜松) () 信誉:100 2002-9-25 12:32:55 得分: 5 删除
取本机的MAC地址可以用NetBios调用来做
回复人:qrlvls(怜松) () 信誉:100 2002-9-25 12:33:47 得分: 2 删除
to xuqelite() :
给我一份
[email protected]
Thanks
回复人:visualliu(liu) () 信誉:100 2002-9-25 13:18:07 得分: 2 删除
也给我一分
[email protected]
回复人:NowCan(能量、激情、雨水、彩虹——雷雨云) () 信誉:100 2002-9-25 13:26:32 得分: 30 删除
#ifndef UNICODE
#define UNICODE
#endif
#include <stdio.h >
#include <assert.h >
#include <windows.h >
#include <lm.h >
int wmain(int argc, wchar_t *argv[])
{
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = -1;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_SERVER; // all servers,据说改成SV_TYPE_SQLSERVER就可以了
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
DWORD i;
if (argc > 2)
{
fwprintf(stderr, L "Usage: %s [\\\\ServerName]\n ", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = argv[1];
//
// Call the NetServerEnum function to retrieve information
// for all servers, specifying information level 101.
//
nStatus = NetServerEnum(pszServerName,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
NULL,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) ¦ ¦ (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries and
// print the data for all server types.
//
for (i = 0; i < dwEntriesRead; i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
fprintf(stderr, "An access violation has occurred\n ");
break;
}
printf( "\tPlatform: %d\n ", pTmpBuf- >sv101_platform_id);
wprintf(L "\tName: %s\n ", pTmpBuf- >sv101_name);
printf( "\tVersion: %d.%d\n ",
pTmpBuf- >sv101_version_major,
pTmpBuf- >sv101_version_minor);
printf( "\tType: %d ", pTmpBuf- >sv101_type);
//
// Check to see if the server is a domain controller;
// if so, identify it as a PDC or a BDC.
//
if (pTmpBuf- >sv101_type & SV_TYPE_DOMAIN_CTRL)
wprintf(L " (PDC) ");
else if (pTmpBuf- >sv101_type & SV_TYPE_DOMAIN_BAKCTRL)
wprintf(L " (BDC) ");
printf( "\n ");
//
// Also print the comment associated with the server.
//
wprintf(L "\tComment: %s\n\n ", pTmpBuf- >sv101_comment);
pTmpBuf++;
dwTotalCount++;
}
// Display a warning if all available entries were
// not enumerated, print the number actually
// enumerated, and the total number available.
if (nStatus == ERROR_MORE_DATA)
{
fprintf(stderr, "\nMore entries available!!!\n ");
fprintf(stderr, "Total entries: %d ", dwTotalEntries);
}
printf( "\nEntries enumerated: %d\n ", dwTotalCount);
}
}
else
fprintf(stderr, "A system error has occurred: %d\n ", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}
连接到服务器是什么意思?
回复人:ancienttale(voidman) () 信誉:100 2002-9-25 13:29:19 得分: 26 删除
枚举计算机可以用
WNetOpenEnum和
WNetEnumResource
有域名和主机名,
取ip可以用gethostbyname
取mac在2000以上可以用sendARP
也可以用netbios
回复人:rocshaw(太阳鸟) () 信誉:100 2002-9-25 13:44:07 得分: 0 删除
这样可以枚举非WINDOWS的计算机吗
回复人:siweioaid(以了) () 信誉:100 2002-9-26 9:31:08 得分: 0 删除
如果你用的是winsocket编程,那么在socket类中就一个结构中存有所有与
其相連的客户的信息。
试试“网络执法官”:http://www.netsofter.com
对于非Windows系统,ping是个好办法。
BOOL CListUserIP::Enumerate(LPNETRESOURCE lpNetRC_p)
{
DWORD dwScope = RESOURCE_GLOBALNET ;
DWORD dwType = RESOURCETYPE_ANY ;
HANDLE hNet = 0;
DWORD dwResult = WNetOpenEnum(dwScope,dwType,0,lpNetRC_p, &hNet) ;
if( dwResult != NO_ERROR )
return FALSE;
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpnrLocal = 0;
BOOL bRet = TRUE;
do
{
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;
dwResult = WNetEnumResource(hNet,&dwEntries,lpnrLocal,&dwBuffer) ;
if( dwResult == NO_ERROR )
{
for( DWORD i = 0 ; i < dwEntries ; i++ )
{
CString nsname;
nsname = lpnrLocal[i].lpRemoteName;
if(lpnrLocal[i].dwDisplayType == RESOURCEDISPLAYTYPE_SERVER)
{
nsname=nsname.Right(nsname.GetLength()-2);
lst_ip.InsertItem(i+1,nsname);
}
if( RESOURCEUSAGE_CONTAINER ==(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) &&
lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER )
if( !Enumerate( &lpnrLocal[i]) )
return FALSE;
}
} else if( dwResult != ERROR_NO_MORE_ITEMS )
return FALSE;
} while( dwResult != ERROR_NO_MORE_ITEMS );
if( lpnrLocal )
GlobalFree((HGLOBAL) lpnrLocal) ;
WNetCloseEnum(hNet) ;
return bRet;
}
void CListUserIP::GetIP()
{
if(lst_ip.GetItemCount()<=1)
return;
CString m_user;
hostent *Me_Info;
for(int i=0;i<lst_ip.GetItemCount();i++)
{
m_user=lst_ip.GetItemText(i,0);
Me_Info=::gethostbyname(m_user);
if(Me_Info!=NULL)
lst_ip.SetItemText(i,1,::inet_ntoa(*(struct in_addr*)Me_Info->h_addr_list[0]));
}
}
声明:
以上两个函数摘自黄森堂的例程中,我才学Winsock编程两天,写不出来.