zoukankan      html  css  js  c++  java
  • 获取网卡信息

    #include <stdio.h>
    #include <windows.h>
    #include <stdlib.h>
    #include <malloc.h>
    #include "Iphlpapi.h"
    
    #pragma comment(lib,"IPHLPAPI.LIB")
    
    int main()
    {
        PIP_ADAPTER_INFO pAdapterInfo;
        PIP_ADAPTER_INFO pAdapter   = NULL;
        DWORD dwRetVal              =        0;
    
        pAdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(PIP_ADAPTER_INFO));
        ULONG ulOutBufLen = sizeof(PIP_ADAPTER_INFO);
    
        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("Adapter Name:\t%s\n",pAdapter->AdapterName);
                printf("Adapter Desc:\t%s\n",pAdapter->Description);
                printf("Adapter Addr:\t%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x",
                    pAdapter->Address[0],pAdapter->Address[1],pAdapter->Address[2],
                    pAdapter->Address[3],pAdapter->Address[4],pAdapter->Address[5]);
                printf("IP Address:\t%s\n",pAdapter->IpAddressList.IpAddress.String);
                printf("IP Mask:\t%s\n",pAdapter->IpAddressList.IpMask.String);
                printf("GateWay:\t%s\n",pAdapter->GatewayList.IpAddress.String);
                printf("**********************\n");
    
                if(pAdapter->DhcpEnabled)
                {
                    printf("DHCP Enabled : YES\n");
                    printf("\tDHCP Server:\t%s\n",pAdapter->DhcpServer.IpAddress.String);
                    printf("Lease Obtained:%ld\n",pAdapter->LeaseObtained);
                }
                else
                {
                    printf("DHCP Enabled : NO \n");
                }
    
    
                if(pAdapter->HaveWins)
                {
                    printf("Have Wins : YES");
                    printf("\tPrimary Wins Server :\t%s\n",pAdapter->PrimaryWinsServer.IpAddress.String);
                    printf("\tSecondary Wins Server : \t%s\n",pAdapter->SecondaryWinsServer.IpAddress.String);
                }
                else
                {
                    printf("Have Wins :NO\n");
                }
    
                pAdapter = pAdapter->Next;
            }
        }
        else
        {
            printf("Call to GetAdaptersInfo failed\n");
        }
        return 0;
    }

    ..

  • 相关阅读:
    在Unix上使用管道压缩exp导出文件
    自制CPU的黑暗历程一
    Error C1189: #error: Please use the /MD switch for _AFXDLL builds
    Redis乐观锁解决高并发抢红包的问题
    PHP分页类
    汇编基础——使用nasm和bochs学习汇编
    数据同步工具DBsync
    完成端口的一些教程
    sdf
    (转)C#(WIN FORM)两个窗体间LISTVIEW值的修改
  • 原文地址:https://www.cnblogs.com/tk091/p/2752803.html
Copyright © 2011-2022 走看看