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;
    }

    ..

  • 相关阅读:
    在页面生命周期执行时 Page 对象在 SaveState 阶段都发生了什么事?
    接收Firfox RESTClient #Post请求
    c# 单例模式[Singleton]之深夜闲聊
    JQuery 之 Ajax 异步和同步浅谈
    [模板]数学整合
    Yandex插件使用说明——Slager_Z
    模板练习(LUOGU)
    数学整合 新(LUOGU)
    [NOI.AC]DELETE(LIS)
    [NOI.AC]COUNT(数学)
  • 原文地址:https://www.cnblogs.com/tk091/p/2752803.html
Copyright © 2011-2022 走看看