zoukankan      html  css  js  c++  java
  • 获取网卡地址

    如何获取网卡地址(MAC地址):

    VC++编写的代码,适用于windows环境,API实现

    /*char *pMACAdr,返回网卡地址的buff,

     int *nBuffLen前一个参数的长度,

     int nAdapterID = 0网卡号,针对多网卡问题,有的机器不止一个网卡,默认为0

    */

    #include <NB30.H>
    #pragma comment(lib, "C:\Program Files\Microsoft Visual Studio\VC98\Lib\Netapi32.lib")//自己找安装目录

    BOOL GetMACAdress(char *pMACAdr, int *nBuffLen, int nAdapterID = 0)
    {
     if (NULL == pMACAdr || *nBuffLen <= 0 || nAdapterID < 0) {
      *nBuffLen = 0;
      return FALSE;
     }
     memset(pMACAdr, 0, *nBuffLen);

     typedef struct _ASTAT_   
     {   
      ADAPTER_STATUS   adapt;   
      NAME_BUFFER      NameBuff   [30];   
     }ASTAT, *PASTAT; 

     NCB  ncb;   
     UCHAR   uRetCode;   
     ASTAT   Adapter; 
     
     memset(&ncb, 0, sizeof(ncb));   
     ncb.ncb_command  = NCBRESET;   
     //网卡序号,一般从0开始
     ncb.ncb_lana_num = nAdapterID;  
     
     //send one NCBRESET command to the adapter car, for initialzing
     uRetCode = Netbios(&ncb);      
     memset(&ncb, 0, sizeof(ncb));   
     ncb.ncb_command  = NCBASTAT;   
     ncb.ncb_lana_num = nAdapterID;//specify the adapter car ID  
        
     strcpy((char*)ncb.ncb_callname, "* ");   
     ncb.ncb_buffer = (PUCHAR)&Adapter;       
     ncb.ncb_length = sizeof(Adapter);   
        
     //send the NCBRESET command to get the adapter car msg  
     uRetCode = Netbios(&ncb); 
     CString szMacAdr;  
     if(0 == uRetCode) {   //获得网卡信息成功
      szMacAdr.Format("%02X%02X-%02X%02X-%02X%02X",  
       Adapter.adapt.adapter_address[0],   
       Adapter.adapt.adapter_address[1],   
       Adapter.adapt.adapter_address[2],   
       Adapter.adapt.adapter_address[3],   
       Adapter.adapt.adapter_address[4],   
       Adapter.adapt.adapter_address[5]  
       );
     }
     if (szMacAdr.IsEmpty())  {
      *nBuffLen = 0;
      return FALSE;
     }
     else{
      int nMacLen = szMacAdr.GetLength();
      *nBuffLen = nMacLen <= *nBuffLen ? nMacLen : *nBuffLen;
      memcpy(pMACAdr, szMacAdr.GetBuffer(*nBuffLen), *nBuffLen);
      return TRUE;
     }
    }

    如果想现存的DLL或者ActiveX控制, 在我的资源里有封装好的DLL与ActiveX控制下载, 直接调用接口使用即可

  • 相关阅读:
    CSRF攻击原理
    大前端
    尊敬自己,才能拥有改变的力量
    重温尼采语录 序章
    人生的弹性 -- 观《聚宝盆》有感
    求学梦
    爱国情怀
    雾中见我
    找东西
    走在路上的感悟
  • 原文地址:https://www.cnblogs.com/MingoJiang/p/8682212.html
Copyright © 2011-2022 走看看