VC++中怎样vba 读取网卡 mac地址的MAC地址

博客访问: 339791
博文数量: 116
博客积分: 3160
博客等级: 中校
技术积分: 1972
注册时间:
低调、勤奋。
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: C/C++ 10:47:41
获取mac地址的方法,关键是要那个头文件,其它比较简单。代码如下:/*begin*/#include "stdio.h"#include "stdlib.h"#include "windows.h"#include "Iphlpapi.h"#pragma comment(lib, "Iphlpapi.lib")#define & UNICODE&#define snprintf _snprintfbool GetLoaclMac(){&& &DWORD & & & & & &&& &DWORD & & & & & & adapterinfosize=0;&& &PIP_ADAPTER_INFO & &&& &PIP_ADAPTER_INFO & &pAdapter = NULL;&& &PIP_ADAPTER_INFO & &pNextAdapter = NULL;&& &&& &if((err=GetAdaptersInfo(NULL,&adapterinfosize))!=0)&& &{&& & & &if(err!=ERROR_BUFFER_OVERFLOW)&& & & &{&& & & & & &printf("GetAdapterInfo 大小错误: %d\n",GetLastError());&& & & & & &&& & & &}&& &}&& &&& &if((padapterinfo=(PIP_ADAPTER_INFO)GlobalAlloc(GPTR,adapterinfosize))==NULL)&& &{&& & & &printf("内存分配错误: %d\n",GetLastError());&& & & &&& &}&& &&& &if((err=GetAdaptersInfo(padapterinfo,&adapterinfosize))!=0)&& &{&& & & &printf("GetAdaptersInfo 错误: %d\n",GetLastError());&& & & &GlobalFree(padapterinfo);&& & & &&& &}&& &pNextAdapter =&& &pAdapter = pNextA&& &bool FindRealAdapter = char *macaddr[10]; char temp[100];&& &for (int i = 1;pNextAi++)&& &{&& & & &pAdapter = pNextA&& & & &pNextAdapter = pNextAdapter->N&& & & &printf("找到网卡: %s\n", pAdapter->Description);&& & & &BYTE* hostmac = pAdapter->A&& & & // printf("网卡地址: %.2X-%.2X-%.2X-%.2X-%.2X-%.2X\n",&& & & & &//hostmac[0],hostmac[1],hostmac[2],hostmac[3],hostmac[4],hostmac[5]);
snprintf(temp,sizeof(temp),"%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",hostmac[0],hostmac[1],
hostmac[2],hostmac[3],hostmac[4],hostmac[5]); // memcpy(macaddr[i],temp,sizeof(macaddr[i]));
//memset(temp,'\0',sizeof(temp));
printf("网卡地址:%s\n",temp);
}&& &GlobalFree(padapterinfo);&& &}void main(){
GetLoaclMac();}附件为所程序所需要的库文件,拷到对应的include和lib目录即可。
文件:iphlpapi.h%E5%92%8Clib%E4%BB%A5%E5%8F%8A%E5%BF%85%E9%A1%BB%E6%96%87%E4%BB%B6.rar
阅读(1642) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
请登录后评论。VC++中怎样读取网卡的MAC地址_百度知道
VC++中怎样读取网卡的MAC地址
我有更好的答案
(GetAdaptersInfo(AdapterInfo,&&DWORD&dwBufLen&=&sizeof(AdapterInfo);&&&AdapterInfoIP_ADAPTER_INFO&ptr&=&for&(IP_ADAPTER_INFO*&&//&&if&ptr-&gt!=&NULL;&Address里就保存了网卡的MAC地址&&&&ptr-&&dwBufLen)&==&ERROR_SUCCESS)&{&&&&&&ptr&;next)&{&ptr&=&AdapterInfo[16]
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。您现在的位置:&>&&>&&>&
育龙网&WWW.CHINA-B.C0M&& 日&&来源:互联网
核心提示:
// need include file: #include Nb30.h// need libary: Netapi32.lib int GetAllLocalAdapterMacAddr(std::liststd::vectorunsi
// need include file: #include Nb30.h// need libary: Netapi32.lib int GetAllLocalAdapterMacAddr(std::liststd::vectorunsigned char
mac){ NCBLANA_ENUM AdapterLmemset(ncb, 0, sizeof(ncb));ncb.ncb_command = NCBENUM;ncb.ncb_buffer = (unsigned char *)AdapterLncb.ncb_length = sizeof(AdapterList);Netbios(ncb);mac.resize(0);for (int i = 0; i
AdapterList. ++i ){struct ASTAT{ ADAPTER_STATUSNAME_BUFFER psz_name[30];} A // Reset the LAN adapter so that we can begin querying itNCB Nmemset( Ncb, 0, sizeof (Ncb));Ncb.ncb_command = NCBRESET;Ncb.ncb_lana_num = AdapterList.lana[i]; if (Netbios(Ncb) != NRC_GOODRET) // Prepare to get the adapter status blockmemset(Ncb, 0, sizeof(Ncb)) ;Ncb.ncb_command = NCBASTAT;Ncb.ncb_lana_num = AdapterList.lana[ i ];strcpy((char *)Ncb.ncb_callname, "*" ); memset(Adapter, 0, sizeof (Adapter));Ncb.ncb_buffer = (unsigned char *)ANcb.ncb_length = sizeof (Adapter); // Get the adapter‘s info and, if this works, return it in standard,// colon-delimited form. if ( Netbios( Ncb ) == 0 ){ std::vectorunsigned char v6;v6.resize(6);for (int i=0; i6; i++) v6[i] = Adapter.adapt.adapter_address[i];if (v6[0] == 0){ std::liststd::vectorunsigned char ::iterator i = mac.begin();for (; i!=mac.end(); i++) if (*i == v6)if (i==mac.end())mac.push_back(v6);}}else}return 0;}
相关热词搜索:
-- 本站部分信息来源于互联网,不代表本站观点或立场,如有侵权,请来电告知,我们将及时处理如何得到正在使用网卡的MAC地址API
[问题点数:66分,结帖人dingdingko]
如何得到正在使用网卡的MAC地址API
[问题点数:66分,结帖人dingdingko]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2009年12月 VC/MFC大版内专家分月排行榜第一2009年11月 VC/MFC大版内专家分月排行榜第一2009年10月 VC/MFC大版内专家分月排行榜第一2009年9月 VC/MFC大版内专家分月排行榜第一
2009年8月 VC/MFC大版内专家分月排行榜第二
匿名用户不能发表回复!|PIP_ADAPTER_INFO pAdapterI
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;
/* variables used to print DHCP time info */
char buffer[32];
ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
}// Make an initial call to GetAdaptersInfo to get// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
FREE(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(ulOutBufLen);
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
pAdapter = pAdapterI
while (pAdapter) {
if (pAdapter-&DhcpEnabled) {
printf("\t
Lease Obtained: ");
/* Display local time
error = _localtime32_s(&newtime, (__time32_t*) &pAdapter-&LeaseObtained);
if (error)
printf("Invalid Argument to _localtime32_s\n");
// Convert to an ASCII representation
error = asctime_s(buffer, 32, &newtime);
if (error)
printf("Invalid Argument to asctime_s\n");
asctime_s returns the string terminated by \n\0
printf("%s", buffer);
if( pAdapter-&LeaseObtained & 10 ){
for (i = 0; i & pAdapter-&AddressL i++) {
if (i == (pAdapter-&AddressLength - 1))
printf("%.2X\n", (int) pAdapter-&Address[i]);
printf("%.2X-", (int) pAdapter-&Address[i]);
pAdapter = pAdapter-&N
printf("\n");
printf("GetAdaptersInfo failed with error: %d\n", dwRetVal);
if (pAdapterInfo)
FREE(pAdapterInfo);
阅读(...) 评论()

我要回帖

更多关于 远程桌面读取网卡 的文章

 

随机推荐