找回密码
 立即注册
使用GetAdaptersInfo获取网卡详细信息(包括:AdapterName,Mac,Ip,NetMask,NetGate)
#includelt;winsock2.hgt;
#includelt;Iphlpapi.hgt;
#includelt;stdio.hgt;
#pragmacomment(lib,Iphlpapi.lib)
intmain()
{
PIP_ADAPTER_INFOpAdapterInfo;
PIP_ADAPTER_INFOpAdapter=NULL;
DWORDdwRetVal=0;
ULONGulOutBufLen;
pAdapterInfo=(PIP_ADAPTER_INFO)malloc(sizeof(IP_ADAPTER_INFO));
ulOutBufLen=sizeof(IP_ADAPTER_INFO);
//首次调用GetAdapterInfo获取ulOutBufLen大小
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(AdapterName:\t%s\n,pAdapter-gt;AdapterName);
printf(AdapterDesc:\t%s\n,pAdapter-gt;Description);
printf(MACAddr:\t%02x-%02x-%02x-%02x-%02x-%02x\n,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address);
printf(IPAddress:\t%s\n,pAdapter-gt;IpAddressList.IpAddress.String);
printf(IPMask:\t%s\n,pAdapter-gt;IpAddressList.IpMask.String);
printf(Gateway:\t%s\n,pAdapter-gt;GatewayList.IpAddress.String);
pAdapter=pAdapter-gt;Next;
}
}
else
{
printf(CalltoGetAdaptersInfofailed.\n);
}
}

(Use GetAdaptersInfo to get network card details (including: AdapterName, Mac, Ip, NetMask, NetGate)
#includelt;winsock2.hgt;
#includelt;Iphlpapi.hgt;
#includelt;stdio.hgt;
#pragmacomment(lib, Iphlpapi.lib)
intmain()
{
PIP_ADAPTER_INFOpAdapterInfo;
PIP_ADAPTER_INFOpAdapter=NULL;
DWORDdwRetVal=0;
ULONGulOutBufLen;
pAdapterInfo=(PIP_ADAPTER_INFO)malloc(sizeof(IP_ADAPTER_INFO));
ulOutBufLen=sizeof(IP_ADAPTER_INFO);
//Call GetAdapterInfo for the first time to get the size of ulOutBufLen
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(AdapterName:\t%s\n,pAdapter-gt;AdapterName);
printf(AdapterDesc:\t%s\n,pAdapter-gt;Description);
printf(MACAddr:\tx-x-x-x-x-x\n,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address,
pAdapter-gt;Address);
printf(IPAddress:\t%s\n,pAdapter-gt;IpAddressList.IpAddress.String);
printf(IPMask:\t%s\n,pAdapter-gt;IpAddressList.IpMask.String);
printf(Gateway:\t%s\n,pAdapter-gt;GatewayList.IpAddress.String);
pAdapter=pAdapter-gt;Next;
}
}
else
{
printf(CalltoGetAdaptersInfofailed.\n);
}
})

[下载]17123654248.rar




上一篇:高质量C编程指南
下一篇:C语言名题精选百则