VC如何获取adsl分配的IP

来源:百度知道 编辑:UC知道 时间:2024/06/01 04:26:01
如题。

#include <iphlpapi.h>
#pragma comment (lib, "iphlpapi")

//m_list是一个ListView控件变量

m_list.ModifyStyle(0, LVS_REPORT);
m_list.ModifyStyleEx(0, LVS_EX_GRIDLINES);
m_list.InsertColumn(0, _T("IP 列表"), LVCFMT_LEFT, 150, 0);
m_list.InsertColumn(1, _T("网络描述"), LVCFMT_LEFT, 200, 0);

DWORD dwRow = 0;

PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO;
ULONG ulSize = sizeof(IP_ADAPTER_INFO);
if (GetAdaptersInfo(pIpAdapterInfo, &ulSize) != NO_ERROR) {
delete pIpAdapterInfo;
pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[ulSize];
}

if (GetAdaptersInfo(pIpAdapterInfo, &ulSize) == NO_ERROR) {
PIP_ADAPTER_INFO pCur = pIpAdapterInfo;
while (pCur) {
CString strIp, strText;
MultiByteToWideChar(CP_ACP, 0, pCur->IpAddressList.IpAddress.String, -1, strIp.GetBuffer(16), 16);
strIp.ReleaseBuffer();
strText.Format(_T("IP Address(%d): %s&q