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

  • 相关阅读:
    阿铭每日一题 day 1 20180111
    计算机网络之基础链路
    android学习笔记 对话框合集
    android 音乐播放器简单实现
    Service的生命周期&Service绑定方法
    android学习笔记 Service
    android学习笔记 activity生命周期&任务栈&activity启动模式
    android 短信助手demo
    android 显示意图
    java 多线程断点下载demo
  • 原文地址:https://www.cnblogs.com/newworldcom/p/4109174.html
Copyright © 2011-2022 走看看