码迷,mamicode.com
首页 > 其他好文 > 详细

获取本地计算机的主机信息

时间:2015-01-23 10:52:04      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
 
#include "IPhelper/Iphlpapi.h"
#pragma comment(lib, "IPhelper/IPHLPAPI.LIB")
 
 
DWORD dwLen = 0, dwError;
 dwError = GetAdaptersInfo(NULL, &dwLen);
 pIPHelper = (PIP_ADAPTER_INFO)malloc(dwLen);
 dwError = GetAdaptersInfo(pIPHelper, &dwLen);
 
 CString strMAC;
 strMAC.Format("%02X-%02X-%02X-%02X-%02X-%02X", pIPHelper->Address[0],\
     pIPHelper->Address[1], pIPHelper->Address[2], pIPHelper->Address[3],\
     pIPHelper->Address[4], pIPHelper->Address[5]);
 PIP_ADDR_STRING pAddrList = &pIPHelper->IpAddressList;
 CString m_IpAddress ="";
 while(pAddrList != NULL)
 {
   CString strAddr = pAddrList->IpAddress.String;
   pAddrList = pAddrList->Next;
   m_comAddr.AddString(strAddr);
 }
 CString strSubMask, strGateway;
 strSubMask.Format("%s", pIPHelper->IpAddressList.IpMask.String);
 strGateway.Format("%s", pIPHelper->GatewayList.IpAddress.String);
 m_strMac = strMAC;
 m_strSub = strSubMask;
 m_strGate = strGateway;
 m_comAddr.SetCurSel(0);
 free(pIPHelper);

获取本地计算机的主机信息

标签:

原文地址:http://www.cnblogs.com/liaocheng/p/4243482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!