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

  • 相关阅读:
    windows中administrator 和 administrators两个账户的区别
    如何去掉打印网页时自带的网址以及页码等内容
    Oracle左连接,右连接
    oracle服务器本地能够登录但是局域网内其他机器不能访问的解决方法
    错误Name node is in safe mode的解决方法
    oracle数据库中对varchar类型求max的解决方法
    JBoss中配置数据源出现错误:“Failed to register driver for: com.mysql.jdbc.Driver”的解决方法
    学习junit和hamcrest的使用
    Ubuntu10.10如何给用户添加sudo权限
    ORACLE 9i卸载并重新安装
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/3003818.html
Copyright © 2011-2022 走看看