怎样获取局域网IP
本人正在做一个基于VC的C/S毕业设计。各位大侠请问怎样获取局域网其他计算机的IP地址并在服务器里面显示出来啊?谢谢 --------------------编程问答-------------------- 你可以参考下,写的很详了http://topic.csdn.net/u/20080518/14/1dfc5618-09d5-49ee-a64e-3c599b836fb2.html --------------------编程问答-------------------- http://topic.csdn.net/u/20100814/23/5d8ded5c-7703-4752-aae2-83826c982cb3.html --------------------编程问答-------------------- --------------------编程问答-------------------- void FindAllComputer(CStringArray& MyList, CStringArray& MyListName)
{
MyList.RemoveAll();
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 StrHostName[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( StrHostName, strlen( StrHostName ) );
MyListName.Add(StrHostName);
//由主机名获得跟它对应的主机信息
host = gethostbyname(strFullName);
if(host == NULL) continue;
ptr = (struct in_addr *) host->h_addr_list[0];
// 获得机器的IP地址
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);
MyList.Add(StrTemp);
}
}
}
delete Buffer;
WNetCloseEnum( hEnum );
}
WSACleanup();
} --------------------编程问答-------------------- --------------------编程问答-------------------- IP 扫描,对局域网地址段扫描
补充:.NET技术 , VC.NET