#include <windows.h>
#include <stdio.h>
#include <iphlpapi.h> //需要安装Microsoft Platform SDK
#pragma
comment
(lib,"C:\\Program Files\\Microsoft Platform SDK\\Lib\\iphlpapi.lib")
int main(void)
{
PIP_ADAPTER_INFO pAdapterInfo ;
PIP_ADAPTER_INFO pAdapter = NULL ;
DWORD dwRetVal = 0 ;
//为适配器结构申请内存
pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) ) ;
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO) ;
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
{
free(pAdapterInfo) ;
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen) ;
}
//获取本地适配器结构信息
if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
{
//以链表形式输出结构信息
pAdapter = pAdapterInfo ;
while (pAdapter)
{
printf("\t网卡名: \t%s\n", pAdapter->AdapterName) ;
printf("\t对网卡的描述: \t%s\n", pAdapter->Description) ;
printf("\t物理地址: \t%ld\n", pAdapter->Address) ;
printf("\tIP地址: \t%s\n", pAdapter->IpAddressList.IpAddress.String) ;
printf("\tIP掩码: \t%s\n", pAdapter->IpAddressList.IpMask.String) ;
printf("\t网关地址链表: \t%s\n", pAdapter->GatewayList.IpAddress.String) ;
printf("\t***\n") ;
if (pAdapter->DhcpEnabled)
{
printf("\tDHCP服务开启: Yes\n") ;
printf("\t\tDHCP服务: \t%s\n", pAdapter->DhcpServer.IpAddress.String) ;
printf("\t租赁信息: %ld\n", pAdapter->LeaseObtained) ;
}
else
printf("\tDHCP服务开启: No\n") ;
if (pAdapter->HaveWins)
{
printf("\t启用Wins: Yes\n") ;
printf("\t\t主WINS地址: \t%s\n", pAdapter->PrimaryWinsServer.IpAddress.String) ;
printf("\t\t辅WINS地址: \t%s\n", pAdapter->SecondaryWinsServer.IpAddress.String) ;
}
else
printf("\t启用Wins: No\n") ;
pAdapter = pAdapter->Next ;
}
}
else
{
printf("GetAdaptersInfo函数调用失败.\n") ;
}
return 0 ;
}
[[it] 本帖最后由 cdmalcl 于 2008-4-28 11:31 编辑 [/it]]