Results 1 to 3 of 3

Thread: Does This Work ?

  1. #1

    Thread Starter
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423

    Question Does This Work ?

    Code:
    Option Explicit
    
    Private Const NCBNAMSZ = 16
    Private Const MAX_LANA = 254
    Private Const NCBENUM = &H37
    Private Const NCBRESET = &H32
    Private Const NCBASTAT = &H33
    
    Private Type ADAPTER_STATUS
        adapter_address(0 To 5) As Byte
        rev_major As Byte
        reserved0 As Byte
        adapter_type As Byte
        rev_minor As Byte
        duration As Integer
        frmr_recv As Integer
        frmr_xmit As Integer
        iframe_recv_err As Integer
        xmit_aborts As Integer
        xmit_success As Long
        recv_success As Long
        iframe_xmit_err As Integer
        recv_buff_unavail As Integer
        t1_timeouts As Integer
        ti_timeouts As Integer
        reserved1 As Long
        free_ncbs As Integer
        max_cfg_ncbs As Integer
        max_ncbs As Integer
        xmit_buf_unavail As Integer
        max_dgram_size As Integer
        pending_sess As Integer
        max_cfg_sess As Integer
        max_sess As Integer
        max_sess_pkt_size As Integer
        name_count As Integer
    End Type
    
    Private Type NAME_BUFFER
        name_(0 To NCBNAMSZ - 1) As Byte
        name_num As Byte
        name_flags As Byte
    End Type
     
    Private Type ASTAT
        adapt As ADAPTER_STATUS
        NameBuff(0 To 29) As NAME_BUFFER
    End Type
    
    Private Type NCB
        ncb_command As Byte
        ncb_retcode As Byte
        ncb_lsn As Byte
        ncb_num As Byte
        p_ncb_buffer As Long
        ncb_length As Integer
        ncb_callname(0 To NCBNAMSZ - 1) As Byte
        ncb_name(0 To NCBNAMSZ - 1) As Byte
        ncb_rto As Byte
        ncb_sto As Byte
        p_ncb_post As Long
        ncb_lana_num As Byte
        ncb_cmd_cplt As Byte
        ncb_reserve(0 To 10 - 1) As Byte
        ncb_event As Long
    End Type
     
    Private Type LANA_ENUM
        length As Byte
        lana(0 To MAX_LANA - 1) As Byte
    End Type
     
    Private Declare Function Netbios Lib "netapi32.dll" _
            (pncb As NCB) As Byte
    Private Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
       (dest As Any, src As Any, ByVal length As Long) As Long
    
    Public Sub GetMacAddress(colMacAddress As Collection)
    
        Dim Adapter As ASTAT
        Dim SNcb As NCB
        Dim uRetCode As Byte
        Dim NetName(0 To 49) As Byte
        Dim Blank(Len(SNcb)) As Byte
        Dim Blank2(Len(Adapter)) As Byte
        Dim lenum As LANA_ENUM
        Dim i As Long
        Dim j As Long
        Dim sMac As String
    
        CopyMemory SNcb, Blank(0), Len(SNcb)
        With SNcb
            .ncb_command = NCBENUM
            .p_ncb_buffer = VarPtr(lenum)
            .ncb_length = Len(lenum)
        End With
        uRetCode = Netbios(SNcb)
        
        For i = 0 To lenum.length - 1
            CopyMemory SNcb, Blank(0), Len(SNcb)
            With SNcb
                .ncb_command = NCBRESET
                .ncb_lana_num = lenum.lana(i)
            End With
        
            uRetCode = Netbios(SNcb)
            
            CopyMemory SNcb, Blank(0), Len(SNcb)
            CopyMemory Adapter, Blank2(0), Len(Adapter)
            With SNcb
                .ncb_command = NCBASTAT
                .ncb_lana_num = lenum.lana(i)
                .p_ncb_buffer = VarPtr(Adapter)
                .ncb_length = Len(Adapter)
                .ncb_callname(0) = Asc("*")
                For j = 1 To 15
                    .ncb_callname(j) = Asc(" ")
                Next
            End With
            uRetCode = Netbios(SNcb)
            If uRetCode = 0 Then
                With Adapter.adapt
                    sMac = Right("00" & Hex(.adapter_address(0)), 2) & _
                           Right("00" & Hex(.adapter_address(1)), 2) & _
                           Right("00" & Hex(.adapter_address(2)), 2) & _
                           Right("00" & Hex(.adapter_address(3)), 2) & _
                           Right("00" & Hex(.adapter_address(4)), 2) & _
                           Right("00" & Hex(.adapter_address(5)), 2)
                End With
                colMacAddress.Add sMac
            End If
        Next
    End Sub
    How Do I Use This Code

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I simplifed things. I saw no reason to use a Collection, so I removed the parameter, and simply add the mac address to a listbox. Try this
    VB Code:
    1. Private Sub GetMacAddress()
    2.  
    3.     Dim Adapter As ASTAT
    4.     Dim SNcb As NCB
    5.     Dim uRetCode As Byte
    6.     Dim NetName(0 To 49) As Byte
    7.     Dim Blank(Len(SNcb)) As Byte
    8.     Dim Blank2(Len(Adapter)) As Byte
    9.     Dim lenum As LANA_ENUM
    10.     Dim i As Long
    11.     Dim j As Long
    12.     Dim sMac As String
    13.  
    14.     CopyMemory SNcb, Blank(0), Len(SNcb)
    15.     With SNcb
    16.         .ncb_command = NCBENUM
    17.         .p_ncb_buffer = VarPtr(lenum)
    18.         .ncb_length = Len(lenum)
    19.     End With
    20.     uRetCode = Netbios(SNcb)
    21.    
    22.     For i = 0 To lenum.length - 1
    23.         CopyMemory SNcb, Blank(0), Len(SNcb)
    24.         With SNcb
    25.             .ncb_command = NCBRESET
    26.             .ncb_lana_num = lenum.lana(i)
    27.         End With
    28.    
    29.         uRetCode = Netbios(SNcb)
    30.        
    31.         CopyMemory SNcb, Blank(0), Len(SNcb)
    32.         CopyMemory Adapter, Blank2(0), Len(Adapter)
    33.         With SNcb
    34.             .ncb_command = NCBASTAT
    35.             .ncb_lana_num = lenum.lana(i)
    36.             .p_ncb_buffer = VarPtr(Adapter)
    37.             .ncb_length = Len(Adapter)
    38.             .ncb_callname(0) = Asc("*")
    39.             For j = 1 To 15
    40.                 .ncb_callname(j) = Asc(" ")
    41.             Next
    42.         End With
    43.         uRetCode = Netbios(SNcb)
    44.         If uRetCode = 0 Then
    45.             With Adapter.adapt
    46.                 sMac = Right("00" & Hex(.adapter_address(0)), 2) & _
    47.                        Right("00" & Hex(.adapter_address(1)), 2) & _
    48.                        Right("00" & Hex(.adapter_address(2)), 2) & _
    49.                        Right("00" & Hex(.adapter_address(3)), 2) & _
    50.                        Right("00" & Hex(.adapter_address(4)), 2) & _
    51.                        Right("00" & Hex(.adapter_address(5)), 2)
    52.             End With
    53.             List1.AddItem sMac
    54.         End If
    55.     Next
    56. End Sub
    57.  
    58. Private Sub Command1_Click()
    59. GetMacAddress
    60. End Sub

  3. #3

    Thread Starter
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423
    The Reason For Having A Collection Was Because I Wanted To Call It From A Module But Thats Easy To Change! Thanx For the Help Hack.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width