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) } }
MFC 获取本机IP地址(多个网卡)
精选 转载下一篇:sed 中使用shell变量
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
获取IP地址
端点(API接口)访问获取IP地址!
IP Java SpringBoot\ -
Windows下获取本机IP地址方法介绍
Windows下获取本机IP地址方法介绍 aa
#if ip地址 #endif i++