• 欢迎访问奇跡の海网站,本站不上传任何资源,所有资源均来自于网络,欢迎加入奇跡の海~!奇跡の海-WordPress QQ群
  • 本站下载资源为网络上收集整理而来,并且以计算机技术研究交流为目的,版权归原作者所有,仅供大家参考,学习,不存在任何商业目的与商业用途.
  • 本站系统镜像均来自于官方原版,ed2k可视为P2P下载链接。所有操作系统默认均为试用版,如有正版密钥可以有效激活,本站不提供任何激活和相关服务。

AU3实用脚本-得到适配器信息(2例)

AutoIT3 奇跡の海 2年前 (2017-08-12) 432次浏览 已收录 0个评论 扫描二维码

得到适配器信息

AU3实用脚本大全获取本地网卡适配器信息

AU3实用脚本-得到适配器信息(2例)

源代码1

$strComputer = "." 
$objWMIService = ObjGet( _ 
"winmgmts:\" & $strComputer & "\root\cimv2") 
$IPConfigSet= $objWMIService.ExecQuery ("Select IPAddress from Win32_NetworkAdapterConfiguration" _ 
& " where IPEnabled=TRUE") 

For $IPConfig in $IPConfigSet 
If Not $IPConfig.IPAddress Then 
For $i=0 To UBound($IPConfig.IPAddress) 
ConsoleWrite( $IPConfig.IPAddress( $i) & @CRLF ) 
Next 
EndIf 
Next

源代码2

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

    //为适配器结构申请内存
    //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;
        }
    }

    //取得本地适配器结构信息
    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("本地网卡适配器信息"));

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

版权声明:本站所有文章和资源使用CC BY-NC-SA 4.0协议授权发布 , 转载应当以相同方式注明文章来自“SeaOMC.COM->AU3实用脚本-得到适配器信息(2例)!在下边可以分享本文哦!
喜欢 (0)
[]
分享 (0)
奇跡の海
关于作者:
一个WordPress菜鸟!
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址