妖哥在吗,上次获取电脑IP地址的子网掩码的程序中怎么筛选出哪一个是有线网络的.
附上次你给的代码.
#include <tchar.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma link "iphlpapi.lib"
void __fastcall TForm1::Button1Click(TObject *Sender)
{
PMIB_IPADDRTABLE pIPTable = NULL;
DWORD dwSize = 0;
::GetIpAddrTable(pIPTable, &dwSize, TRUE);
pIPTable = (PMIB_IPADDRTABLE)::GlobalAlloc(GPTR, dwSize);
::GetIpAddrTable(pIPTable, &dwSize, TRUE);
TCHAR szIPAddr[17], szSubMask[17];
for (DWORD i=0; i < pIPTable->dwNumEntries; i++)
{
// IP
memset(szIPAddr, 0x0, sizeof(szIPAddr));
_stprintf(szIPAddr, TEXT("%d.%d.%d.%d"),
LOWORD(pIPTable->table[i].dwAddr) & 0x00FF,
LOWORD(pIPTable->table[i].dwAddr) >> 8,
HIWORD(pIPTable->table[i].dwAddr) & 0x00FF,
HIWORD(pIPTable->table[i].dwAddr) >> 8);
// Subnet Mask
memset(szSubMask, 0x0, sizeof(szSubMask));
_stprintf(szSubMask, TEXT("%d.%d.%d.%d"),
LOWORD(pIPTable->table[i].dwMask) & 0x00FF,
LOWORD(pIPTable->table[i].dwMask) >> 8,
HIWORD(pIPTable->table[i].dwMask) & 0x00FF,
HIWORD(pIPTable->table[i].dwMask) >> 8);
Memo1->Lines->Add(String().sprintf(TEXT("IP: %s 子网掩码: %s"),
szIPAddr, szSubMask));
}
::GlobalFree(pIPTable);
}
#include <tchar.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma link "iphlpapi.lib"
void __fastcall TForm1::Button1Click(TObject *Sender)
{
PIP_ADAPTER_INFO pAdapterInfo = NULL;
DWORD dwOutBufLen;
if (::GetAdaptersInfo(pAdapterInfo, &dwOutBufLen) == ERROR_BUFFER_OVERFLOW)
pAdapterInfo = (PIP_ADAPTER_INFO)malloc(dwOutBufLen);
if (::GetAdaptersInfo(pAdapterInfo, &dwOutBufLen) == ERROR_SUCCESS) //
{
PIP_ADAPTER_INFO p = pAdapterInfo;
while (p)
{
Memo1->Lines->Add(String().sprintf(TEXT("网卡名称: %s"), p->Description));
Memo1->Lines->Add(String().sprintf(TEXT("网卡类型: %s"),
p->Type == 6? TEXT("有线"): p->Type == 71? TEXT("无线"): TEXT("未知")));
PIP_ADDR_STRING pAddressList = &(p->IpAddressList);
do
{
Memo1->Lines->Add(String().sprintf(TEXT(" IP 地址: %s"),
p->IpAddressList.IpAddress.String));
pAddressList = pAddressList->Next;
} while (pAddressList);
Memo1->Lines->Add(String().sprintf(TEXT("---------- 分隔线 ----------")));
p = p->Next;
}
}
if (pAdapterInfo) free(pAdapterInfo);
}