欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

獲取本地網(wǎng)卡適配器信息具體代碼

 更新時(shí)間:2013年12月31日 16:35:00   作者:  
這篇文章主要介紹了獲取本地網(wǎng)卡適配器信息具體代碼,有需要的朋友可以參考一下

效果如下:

具體代碼如下:

復(fù)制代碼 代碼如下:

#include <Windows.h>
#include <IPHlpApi.h>
#include <stdio.h>

#pragma comment(lib, "IPHlpApi")
#pragma comment(lib, "ws2_32")

int main(int argc, char **argv)
{
    PIP_ADAPTER_INFO pAdapterInfo = NULL;
    ULONG ulLen = sizeof(IP_ADAPTER_INFO);
    struct tm newtime;
    char szBuffer[32];
    errno_t error;

    //為適配器結(jié)構(gòu)申請(qǐng)內(nèi)存
    //pAdapterInfo = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, ulLen);
    pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
    if (NULL == pAdapterInfo)
    {
        printf("Error allocating memory needed to call GetAdaptersInfo.\n");
        return 1;
    }

    if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdapterInfo, &ulLen))
    {
        HeapFree(GetProcessHeap(), 0, pAdapterInfo);
        pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, ulLen);
        if (NULL == pAdapterInfo)
        {
            printf("Error allocating memory needed to call GetAdaptersInfo.\n");
            return 1;
        }
    }

    //取得本地適配器結(jié)構(gòu)信息
    if (ERROR_SUCCESS != GetAdaptersInfo(pAdapterInfo, &ulLen))
    {
        printf("GetAdaptersInfo error!\n");
        return 0;
    }
    if (NULL == pAdapterInfo)
    {
        printf("There is no adapters!\n");
        return 0;
    }

    SetConsoleTitle(TEXT("本地網(wǎng)卡適配器信息"));

    do
    {
        printf("ComboIndex:%d\n", pAdapterInfo->ComboIndex);
        printf("Adapter Name:%s\n", pAdapterInfo->AdapterName);
        printf("Adapter Desc:%s\n", pAdapterInfo->Description);
        printf("Adapter Addr:");
        for (size_t i = 0; i < pAdapterInfo->AddressLength; i++)
        {
            if (i == (pAdapterInfo->AddressLength - 1))
            {
                printf("%02X", (int)pAdapterInfo->Address[i]);
            }
            else
            {
                printf("%02X-", (int)pAdapterInfo->Address[i]);
            }
        }
        printf("\n");
        printf("Index:%d\n", pAdapterInfo->Index);
        printf("Type:");
        switch (pAdapterInfo->Type)
        {
        case MIB_IF_TYPE_OTHER:printf("Other\n"); break;
        case MIB_IF_TYPE_ETHERNET:printf("Ethernet\n"); break;
        case MIB_IF_TYPE_TOKENRING:printf("Token Ring\n"); break;
        case MIB_IF_TYPE_FDDI:printf("FDDI\n"); break;
        case MIB_IF_TYPE_PPP:printf("PPP\n"); break;
        case MIB_IF_TYPE_LOOPBACK:printf("Lookback\n"); break;
        case MIB_IF_TYPE_SLIP:printf("Slip\n"); break;
        default:printf("Unknow type %ld\n", pAdapterInfo->Type); break;
        }
        printf("IP Address:%s\n", pAdapterInfo->IpAddressList.IpAddress.String);
        printf("IP Mask:%s\n", pAdapterInfo->IpAddressList.IpMask.String);
        printf("Gateway:%s\n", pAdapterInfo->GatewayList.IpAddress.String);

        if (pAdapterInfo->DhcpEnabled)
        {
            printf("DHCP Enabled:Yes\n");
            printf("DHCP Server:%s\n", pAdapterInfo->DhcpServer.IpAddress.String);
            printf("Lease Obtained:");
            error = _localtime32_s(&newtime, (__time32_t*)&pAdapterInfo->LeaseObtained);
            if (error)
            {
                printf("Invalid Argument to _localtime32_s.\n");
            }
            else
            {
                error = asctime_s(szBuffer, 32, &newtime);
                if (error)
                {
                    printf("Invalid Argument to asctime_s.\n");
                }
                else
                {
                    printf("%s", szBuffer);
                }
            }

            printf("Lease Expires:");
            error = _localtime32_s(&newtime, (__time32_t*)&pAdapterInfo->LeaseExpires);
            if (error)
            {
                printf("Invalid Argument to _localtime32_s.\n");
            }
            else
            {
                error = asctime_s(szBuffer, 32, &newtime);
                if (error)
                {
                    printf("Invalid Argument to asctime_s.\n");
                }
                else
                {
                    printf("%s", szBuffer);
                }
            }
        }
        else
        {
            printf("DHCP Enabled:No\n");
        }

        if (pAdapterInfo->HaveWins)
        {
            printf("Have Wins:Yes\n");
            printf("Primary Wins Server:%s\n", pAdapterInfo->PrimaryWinsServer.IpAddress.String);
            printf("Secondary Wins Server:%s\n", pAdapterInfo->SecondaryWinsServer.IpAddress.String);
        }
        else
        {
            printf("Have Wins:No\n");
        }

        printf("=================================================================\n");

        pAdapterInfo = pAdapterInfo->Next;
    } while (pAdapterInfo);

    if (pAdapterInfo)
    {
        HeapFree(GetProcessHeap(), 0, pAdapterInfo);
    }

    return 0;
}

相關(guān)文章

  • 用貪心法求解背包問(wèn)題的解決方法

    用貪心法求解背包問(wèn)題的解決方法

    本篇文章是對(duì)用貪心法求解背包問(wèn)題的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C語(yǔ)言完整實(shí)現(xiàn)12種排序算法(小結(jié))

    C語(yǔ)言完整實(shí)現(xiàn)12種排序算法(小結(jié))

    本文主要介紹了C語(yǔ)言完整實(shí)現(xiàn)12種排序算法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • C語(yǔ)言程序中結(jié)構(gòu)體的內(nèi)存對(duì)齊詳解

    C語(yǔ)言程序中結(jié)構(gòu)體的內(nèi)存對(duì)齊詳解

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言程序中結(jié)構(gòu)體的內(nèi)存對(duì)齊的相關(guān)資料,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴可以了解一下
    2022-11-11
  • C語(yǔ)言算法練習(xí)之打魚(yú)還是曬網(wǎng)

    C語(yǔ)言算法練習(xí)之打魚(yú)還是曬網(wǎng)

    這篇文章主要該大家分享C語(yǔ)言打魚(yú)還是曬網(wǎng)的練習(xí),文章主要通過(guò)三天打魚(yú)兩天曬網(wǎng)的俗語(yǔ)提出問(wèn)題,在某一天輪到打魚(yú)還是曬網(wǎng),下面來(lái)看詳細(xì)內(nèi)容吧,需要的朋友可以參考一下
    2022-03-03
  • 一篇文章讓你徹底明白c++11增加的變參數(shù)模板

    一篇文章讓你徹底明白c++11增加的變參數(shù)模板

    C++11的新特性--可變模版參數(shù)(variadic templates)是C++11新增的最強(qiáng)大的特性之一,它對(duì)參數(shù)進(jìn)行了高度泛化,它能表示0到任意個(gè)數(shù)、任意類(lèi)型的參數(shù),這篇文章主要給大家詳細(xì)介紹了關(guān)于c++11增加的變參數(shù)模板的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • 使用C++實(shí)現(xiàn)工資管理中的隨機(jī)教師信息生成功能

    使用C++實(shí)現(xiàn)工資管理中的隨機(jī)教師信息生成功能

    這篇文章主要介紹了使用C++實(shí)現(xiàn)工資管理中的隨機(jī)教師信息生成功能,想要做一個(gè)教師工資管理系統(tǒng),就必須得準(zhǔn)備好數(shù)據(jù),但是這些數(shù)據(jù)如果用手一行一行地敲,那么工作量是非常大的,因此,我就產(chǎn)生了用C語(yǔ)言實(shí)現(xiàn)直接生成大量的教師基本信息的想法,需要的朋友可以參考下
    2023-05-05
  • 關(guān)于C++出現(xiàn)Bus error問(wèn)題的排查與解決

    關(guān)于C++出現(xiàn)Bus error問(wèn)題的排查與解決

    項(xiàng)目代碼中經(jīng)常出現(xiàn)莫名其妙的Bus error問(wèn)題,并且代碼中增加很多try catch 后依然不能將錯(cuò)誤捕獲,一旦Bus erro出現(xiàn),進(jìn)程直接崩潰掉,所以本文給大家介紹了關(guān)于C++出現(xiàn)Bus error問(wèn)題的排查與解決,需要的朋友可以參考下
    2024-01-01
  • 基于C++實(shí)現(xiàn)去除字符串頭尾指定字符功能

    基于C++實(shí)現(xiàn)去除字符串頭尾指定字符功能

    編程時(shí)我們經(jīng)常需要對(duì)字符串進(jìn)行操作,其中有一項(xiàng)操作就是去除字符串的頭(尾)指定的字符,比如空格。本文為大家詳細(xì)介紹了如何利用C++實(shí)現(xiàn)這一效果,需要的可以參考一下
    2022-04-04
  • Atom安裝配置C/C++詳細(xì)教程

    Atom安裝配置C/C++詳細(xì)教程

    Atom (一款開(kāi)源的代碼編輯器)是github專(zhuān)門(mén)為程序員推出的一個(gè)跨平臺(tái)文本編輯器。這篇文章主要介紹了Atom安裝配置C/C++教程,需要的朋友可以參考下
    2020-05-05
  • c++ 解析yaml文件的步驟

    c++ 解析yaml文件的步驟

    這篇文章主要介紹了c++ 解析yaml文件的步驟,幫助大家更好的理解和使用c++,感興趣的朋友可以了解下
    2020-12-12

最新評(píng)論