zoukankan      html  css  js  c++  java
  • vb 获取本机MAC地址

    Public Const MAX_ADAPTER_NAME_LENGTH = 260
    Public Const MAX_ADAPTER_ADDRESS_LENGTH = 8
    Public Const MAX_ADAPTER_DESCRIPTION_LENGTH = 132

    Type IP_ADDR_STRING
    Next As Long
    ipAddress As String * 16
    IpMask As String * 16
    Context As Long
    End Type

    Type IP_ADAPTER_INFO
    Next As Long
    ComboIndex As Long
    AdapterName As String * MAX_ADAPTER_NAME_LENGTH
    Description As String * MAX_ADAPTER_DESCRIPTION_LENGTH
    AddressLength As Long
    Address(MAX_ADAPTER_ADDRESS_LENGTH - 1) As Byte
    Index As Long
    Type1 As Long
    DhcpEnabled As Long
    CurrentIpAddress As Long
    IpAddressList As IP_ADDR_STRING
    GatewayList As IP_ADDR_STRING
    DhcpServer As IP_ADDR_STRING
    HaveWins As Boolean
    PrimaryWinsServer As IP_ADDR_STRING
    SecondaryWinsServer As IP_ADDR_STRING
    LeaseObtained As Long
    LeaseExpires As Long
    End Type

    Public Declare Function GetNetworkParams Lib "IPHlpApi" (FixedInfo As Any, pOutBufLen As Long) As Long
    Public Declare Function GetAdaptersInfo Lib "IPHlpApi" (IpAdapterInfo As Any, pOutBufLen As Long) As Long
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

    Public Function GetMACAddress() As String
        Dim i As Integer, FixedInfoSize&, AdapterInfoSize&
        Dim PhysicalAddress As String
        Dim AdapterInfo As IP_ADAPTER_INFO
        Dim pAdapt As Long

        '获得网络参数
        GetNetworkParams ByVal 0&, FixedInfoSize
        '建立网络参数信息缓冲区
        ReDim FixedInfoBuffer(FixedInfoSize - 1)

        '获取适配器信息
        GetAdaptersInfo ByVal 0&, AdapterInfoSize
        '建立适配器信息缓冲区
        ReDim AdapterInfoBuffer(AdapterInfoSize - 1)

        GetAdaptersInfo AdapterInfoBuffer(0), AdapterInfoSize

        '拷贝AdapterInfo结构
        CopyMemory AdapterInfo, AdapterInfoBuffer(0), Len(AdapterInfo)
        pAdapt = AdapterInfo.Next
            For i = 0 To AdapterInfo.AddressLength - 1
                PhysicalAddress = PhysicalAddress & Format$(Hex$(AdapterInfo.Address(i)), "00")
                If i < AdapterInfo.AddressLength - 1 Then
                    PhysicalAddress = PhysicalAddress & "-"
                End If
            Next
            GetMACAddress = PhysicalAddress
            PhysicalAddress = ""
            pAdapt = AdapterInfo.Next
            '查找下一个网卡
            If pAdapt <> 0 Then
                CopyMemory AdapterInfo, ByVal pAdapt, Len(AdapterInfo)
            End If
    End Function

  • 相关阅读:
    原码、反码、补码以及为什么要用反码和补码
    Linux中的段管理,bss段,data段,
    关于SRAM,DRAM,SDRAM,以及NORFLASH,NANDFLASH
    S3C2440的GPIO
    剑指offer——二叉搜索树与双向链表
    剑指offer——平衡二叉树
    ***剑指offer——字符串的排列(不会)
    剑指offer——两个链表的第一个公共结点
    剑指offer——数组中只出现一次的数字
    剑指offer——最小的K个数
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/3003818.html
Copyright © 2011-2022 走看看