找回密码
 立即注册

使用GetAdaptersInfo获取网卡详细信息(包括:Adapter Name,Mac,

[复制链接]
发表于 2022-9-22 17:12:35 | 显示全部楼层 |阅读模式
资源类型:行业应用 » 企业管理 . 资源来源:网友投递
使用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语言名题精选百则

使用道具 举报

Archiver|手机版|小黑屋|English Version|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved

关于本站 - 版权申明 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表