zoukankan      html  css  js  c++  java
  • 获取本地MAC地址和多IP

     1 #include<atlbase.h>
     2 #include<atlconv.h>
     3 #include"iphlpapi.h"
     4 #pragma comment(lib,"Iphlpapi.lib")
     5 void Get_IP()
     6 {
     7     PIP_ADAPTER_INFO pAdapterInfo;
     8     PIP_ADAPTER_INFO pAdapter = NULL;
     9     DWORD dwRetVal = 0;
    10     pAdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO));
    11     ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
    12     if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS){
    13         //GlobalFree(pAdapterInfo);
    14         pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen);
    15     }
    16     if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR){
    17         pAdapter = pAdapterInfo;
    18         while (pAdapter){
    19             if (strstr(pAdapter->Description, "PCI")>0//pAdapter->Description中包含"PCI"为:物理网卡
    20                 || pAdapter->Type == 71//pAdapter->Type是71为:无线网卡
    21                 ){
    22                 printf("------------------------------------------------------------
    ");
    23                 printf("网卡名称:	%s
    ", pAdapter->AdapterName);
    24                 printf("网卡描述:	%s
    ", pAdapter->Description);
    25                 printf("Gateway:	%s
    ", pAdapter->GatewayList.IpAddress.String);
    26                 printf("网卡MAC地址:	");
    27                 for (UINT i = 0; i<pAdapter->AddressLength; i++){
    28                     printf("%02X%c", pAdapter->Address[i],
    29                         i == pAdapter->AddressLength - 1 ? '
    ' : '-');
    30                 }
    31 
    32                 printf("网卡类型(71为无线网卡,6为物理网卡):	%d
    ", pAdapter->Type);
    33                 printf("IP地址:	%s
    ", pAdapter->IpAddressList.IpAddress.String);
    34                 printf("子网掩码:	%s
    ", pAdapter->IpAddressList.IpMask.String);
    35             }
    36             pAdapter = pAdapter->Next;
    37         }
    38     }
    39     else
    40     {
    41         printf("Call to Get Adapters Information failed
    ");
    42     }
    43 }
    44 
    45 
    46 void main()
    47 {
    48     Get_IP();
    49 }

    http://blog.csdn.net/l00109503/article/details/4044189

  • 相关阅读:
    php 魔鬼训练
    php 验证码
    php 经典分页(推荐和laypage配合)
    php 过时的sql操作库(学习使用)
    php 上传图片
    npm 国内淘宝镜像cnpm、设置淘宝源
    gulp + webpack + sass 学习
    关于分页的解决方案收集
    SVN的学习和安装
    使用和学习 ES2015
  • 原文地址:https://www.cnblogs.com/newworldcom/p/4109174.html
Copyright © 2011-2022 走看看