在windows2000下,如何获取一张网卡上设定的多个IP?

ExitWindows 2003-05-18 10:58:09
windows2000中,一张网卡上可设定多个IP,用什么办法可以获取这些呢?
...全文
48 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqchang 2003-05-19
  • 打赏
  • 举报
回复
同意Skt32(Skt32),我也是这么作的。
tserpent 2003-05-18
  • 打赏
  • 举报
回复
我用iphlp.dll
int LoadNetProperty()
{
unsigned long nError;
nError = GetAdaptersInfo(g_pAdapterInfo,&g_nAdapterLen);
if (nError==ERROR_NO_DATA)
{
AfxMessageBox("没有找到网络适配器",MB_OK|MB_ICONWARNING);
g_pAdapterInfo=NULL;
return -1;
}
if (nError==ERROR_NOT_SUPPORTED)
{
AfxMessageBox("不能获得网络适配器属性",MB_OK|MB_ICONWARNING);
return -1;
}
if (nError==ERROR_BUFFER_OVERFLOW)
{
g_pAdapterInfo= (PIP_ADAPTER_INFO)malloc(g_nAdapterLen);
nError = GetAdaptersInfo(g_pAdapterInfo,&g_nAdapterLen);
if(nError != 0)
{
AfxMessageBox("不能获得网络适配器属性",MB_OK|MB_ICONWARNING);
g_pAdapterInfo=NULL;
return -1;
}
}

char buf[128];
unsigned long ip;
strcpy(buf,pAdapter->IpAddressList.IpAddress.String);

//get next
//pAdapter->IpAddressList.Next

return 0;
}
ExitWindows 2003-05-18
  • 打赏
  • 举报
回复
请教 。
Skt32 2003-05-18
  • 打赏
  • 举报
回复
Following is a code that gets local machine IP addresses. The advantages over the article by Jeff Lundgren are that my code recognises ALL IP addresses and is ready for IPv6 ;-)


char szHostName[128];

if( gethostname(szHostName, 128) == 0 )
{
// Get host adresses
struct hostent * pHost;
int i;

pHost = gethostbyname(szHostName);

for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
CString str;
int j;

for( j = 0; j < pHost->h_length; j++ )
{
CString addr;

if( j > 0 )
str += ".";

addr.Format("%u", (unsigned int)((unsigned
char*)pHost->h_addr_list[i])[j]);
str += addr;
}
// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)
}
}



runbuff 2003-05-18
  • 打赏
  • 举报
回复
楼上的方法好象不行吧。
我在调试状态看,IPHELP函数仅取到了一个IP而已。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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