11585.html
来自「VB技巧问答10000例,是一个教程」· HTML 代码 · 共 27 行
HTML
27 行
<html>
<head>
<title>Re: 请问VB如何取得网路卡的卡号,用API的话行吗?</title>
</head>
<body bgcolor="#FFFFFF" vlink="#808080">
<center>
<h1>Re: 请问VB如何取得网路卡的卡号,用API的话行吗?</h1>
</center>
<hr size=7 width=75%>
<hr size=7 width=75%><p>
Posted by <a href="mailto:dunce@hongkong.com">小莱奥</a> on April 01, 1999 at 11:38:10:<p>
In Reply to: <a href="11561.html">请问VB如何取得网路卡的卡号,用API的话行吗?</a> posted by Andy on March 31, 1999 at 18:16:52:<p>
: 请问VB如何取得网路卡的卡号,我在网路上有找到控制项,但是试用版且无原始码可研究,用API的话行吗,为何NT做的到呢?<p>可以的<br>我刚看了这段code<br>但不知何解,得来的全是00 00 00 00 00 00<p> BAS Module Code <br> <br>Add the following code to a BAS module: <p>--------------------------------------------------------------------------------<br> <p>Option Explicit<p>Public Const NCBASTAT As Long = &H33<br>Public Const NCBNAMSZ As Long = 16<br>Public Const HEAP_ZERO_MEMORY As Long = &H8<br>Public Const HEAP_GENERATE_EXCEPTIONS As Long = &H4<br>Public Const NCBRESET As Long = &H32<p>Public Type NET_CONTROL_BLOCK 'NCB<br> ncb_command As Byte<br> ncb_retcode As Byte<br> ncb_lsn As Byte<br> ncb_num As Byte<br> ncb_buffer As Long<br> ncb_length As Integer<br> ncb_callname As String * NCBNAMSZ<br> ncb_name As String * NCBNAMSZ<br> ncb_rto As Byte<br> ncb_sto As Byte<br> ncb_post As Long<br> ncb_lana_num As Byte<br> ncb_cmd_cplt As Byte<br> ncb_reserve(9) As Byte ' Reserved, must be 0<br> ncb_event As Long<br>End Type<p>Public Type ADAPTER_STATUS<br> adapter_address(5) As Byte<br> rev_major As Byte<br> reserved0 As Byte<br> adapter_type As Byte<br> rev_minor As Byte<br> duration As Integer<br> frmr_recv As Integer<br> frmr_xmit As Integer<br> iframe_recv_err As Integer<br> xmit_aborts As Integer<br> xmit_success As Long<br> recv_success As Long<br> iframe_xmit_err As Integer<br> recv_buff_unavail As Integer<br> t1_timeouts As Integer<br> ti_timeouts As Integer<br> Reserved1 As Long<br> free_ncbs As Integer<br> max_cfg_ncbs As Integer<br> max_ncbs As Integer<br> xmit_buf_unavail As Integer<br> max_dgram_size As Integer<br> pending_sess As Integer<br> max_cfg_sess As Integer<br> max_sess As Integer<br> max_sess_pkt_size As Integer<br> name_count As Integer<br>End Type<br> <br>Public Type NAME_BUFFER<br> name As String * NCBNAMSZ<br> name_num As Integer<br> name_flags As Integer<br>End Type<p>Public Type ASTAT<br> adapt As ADAPTER_STATUS<br> NameBuff(30) As NAME_BUFFER<br>End Type<p>Public Declare Function Netbios Lib "netapi32.dll" _<br> (pncb As NET_CONTROL_BLOCK) As Byte<br> <br>Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _<br> (hpvDest As Any, ByVal _<br> hpvSource As Long, ByVal _<br> cbCopy As Long)<br> <br>Public Declare Function GetProcessHeap Lib "kernel32" () As Long<p>Public Declare Function HeapAlloc Lib "kernel32" _<br> (ByVal hHeap As Long, ByVal dwFlags As Long, _<br> ByVal dwBytes As Long) As Long<br> <br>Public Declare Function HeapFree Lib "kernel32" _<br> (ByVal hHeap As Long, _<br> ByVal dwFlags As Long, _<br> lpMem As Any) As Long<p><br>Public Function GetMACAddress() As String<p> 'retrieve the MAC Address for the network controller<br> 'installed, returning a formatted string<br> <br> Dim tmp As String<br> Dim pASTAT As Long<br> Dim NCB As NET_CONTROL_BLOCK<br> Dim AST As ASTAT<p> 'The IBM NetBIOS 3.0 specifications defines four basic<br> 'NetBIOS environments under the NCBRESET command. Win32<br> 'follows the OS/2 Dynamic Link Routine (DLR) environment.<br> 'This means that the first NCB issued by an application<br> 'must be a NCBRESET, with the exception of NCBENUM.<br> 'The Windows NT implementation differs from the IBM<br> 'NetBIOS 3.0 specifications in the NCB_CALLNAME field.<br> NCB.ncb_command = NCBRESET<br> Call Netbios(NCB)<br> <br> 'To get the Media Access Control (MAC) address for an<br> 'ethernet adapter programmatically, use the Netbios()<br> 'NCBASTAT command and provide a "*" as the name in the<br> 'NCB.ncb_CallName field (in a 16-chr string).<br> NCB.ncb_callname = "* "<br> NCB.ncb_command = NCBASTAT<br> <br> 'For machines with multiple network adapters you need to<br> 'enumerate the LANA numbers and perform the NCBASTAT<br> 'command on each. Even when you have a single network<br> 'adapter, it is a good idea to enumerate valid LANA numbers<br> 'first and perform the NCBASTAT on one of the valid LANA<br> 'numbers. It is considered bad programming to hardcode the<br> 'LANA number to 0 (see the comments section below).<br> NCB.ncb_lana_num = 0<br> NCB.ncb_length = Len(AST)<br> <br> pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _<br> Or HEAP_ZERO_MEMORY, NCB.ncb_length)<br> <br> If pASTAT = 0 Then<br> Debug.Print "memory allocation failed!"<br> Exit Function<br> End If<br> <br> NCB.ncb_buffer = pASTAT<br> Call Netbios(NCB)<br> <br> CopyMemory AST, NCB.ncb_buffer, Len(AST)<br> <br> tmp = Format$(Hex(AST.adapt.adapter_address(0)), "00") & " " & _<br> Format$(Hex(AST.adapt.adapter_address(1)), "00") & " " & _<br> Format$(Hex(AST.adapt.adapter_address(2)), "00") & " " & _<br> Format$(Hex(AST.adapt.adapter_address(3)), "00") & " " & _<br> Format$(Hex(AST.adapt.adapter_address(4)), "00") & " " & _<br> Format$(Hex(AST.adapt.adapter_address(5)), "00")<br> <br> <br> HeapFree GetProcessHeap(), 0, pASTAT<br> <br> GetMACAddress = tmp<p>End Function<br>'--end block--'<br> <p> Form Code <br> <br>To a form add a command button (Command1), and a text box (Text1). Labels and frames are optional. Add the following to the command button: <p>--------------------------------------------------------------------------------<br> <p>Option Explicit<p>Private Sub Command1_Click()<p> Text1 = GetMACAddress()<p>End Sub<p>
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 11585-->
<!--top: 11894--><li><a href="11894.html">Re: 请问VB如何取得网路卡的卡号,用API的话行吗?</a> <b>steven</b> <i>15:56:30 4/12/99</i>
(<!--responses: 11894-->0)
<ul><!--insert: 11894-->
</ul><!--end: 11894-->
</ul><!--end: 11585-->
<br><hr size=7 width=75%><p>
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?