Find the MAC address of the local Nic. Online data code correction

Source: Internet
Author: User

You can create a project first. Then add a class. The following is the code of the class:

Public const ncbastat as long = & h33
Public const ncbnamsz as long = 16
Public const heap_zero_memory as long = & H8
Public const heap_generate_exceptions as long = & h4
Public const ncbreset as long = & H32

Public type net_control_block
Ncb_command as byte
Ncb_retcode as byte
Ncb_lsn as byte
Ncb_num as byte
Ncb_buffer as long
Ncb_length as integer
Ncb_callname as string * ncbnamsz
Ncb_name as string * ncbnamsz
Ncb_rto as byte
Ncb_sto as byte
Ncb_post as long
Ncb_lana_num as byte
Ncb_1__cplt as byte
Ncb_reserve (9) as byte
Ncb_event as long
End type

Public type adapter_status
Adapter_address (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_eclip_sess as integer
Max_sess as integer
Max_sess_pkt_size as integer
Name_count as integer
End type

Public type name_buffer
Name as string * ncbnamsz
Name_num as integer
Name_flags as integer
End type

Public type astat
Adapt as adapter_status
Namebuff (30) as name_buffer
End type

Public declare function NetBIOS lib "netapi32.dll" (PNCB as net_control_block) as byte

Public declare sub copymemory lib "Kernel32" alias "rtlmovememory" (hpvdest as any, byval hpvsource as long, byval cbcopy as long)

Public declare function getprocessheap lib "Kernel32" () as long

Public declare function heapalloc lib "Kernel32" (byval hheap as long, byval dwflags as long, byval dwbytes as long) as long

Public declare function heapfree lib "Kernel32" (byval hheap as long, byval dwflags as long, lpmem as any) as long

Public Function getmacaddress () as string

Dim TMP as string
Dim pastat as long
Dim NCB as net_control_block
Dim ast as astat
NCB. ncb_command = ncbreset
Call NetBIOS (NCB)
NCB. ncb_callname = "*"
NCB. ncb_command = ncbastat
NCB. ncb_lana_num = 0
NCB. ncb_length = Len (AST)
Pastat = heapalloc (getprocessheap (), heap_zero_memory, NCB. ncb_length)

'Pastat = heapalloc (getprocessheap (), heap_generate_exceptions, NCB. ncb_length)

If pastat = 0 then
Debug. Print "memory allocation failed! "
Exit Function
End if

NCB. ncb_buffer = pastat
Call NetBIOS (NCB)

Copymemory AST, NCB. ncb_buffer, Len (AST)

TMP = format $ (hex (AST. Adapt. adapter_address (0), "00 ")&"-"&_
Format $ (hex (AST. Adapt. adapter_address (1), "00 ")&"-"&_
Format $ (hex (AST. Adapt. adapter_address (2), "00 ")&"-"&_
Format $ (hex (AST. Adapt. adapter_address (3), "00 ")&"-"&_
Format $ (hex (AST. Adapt. adapter_address (4), "00 ")&"-"&_
Format $ (hex (AST. Adapt. adapter_address (5), "00 ")

Heapfree getprocessheap (), 0, pastat

Getmacaddress = TMP

End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.