mac address check

gendrix

New member
Local time
Today, 17:05
Joined
Jan 23, 2009
Messages
8
any idea how to perform mac address check with vba script ?
 
thanx for your answer, but the link is broken. do U have any copy for the script ? or any body has the answer ?:)
 
thanx for your answer, but the link is broken. do U have any copy for the script ? or any body has the answer ?:)

The link works for me (IE7), but the text is below
Code:
[COLOR=black][FONT=Verdana][FONT=Courier New][SIZE=3][B]Step-by-Step Example[/B][/SIZE][/FONT][/FONT][/COLOR][FONT=Verdana]

[COLOR=black]
[LIST]
[*][FONT=Courier New][SIZE=3]Create a new Standard EXE from Visual Basic. Form1 is created by default. [/SIZE][/FONT]
[*][FONT=Courier New][SIZE=3]Add a CommandButton to Form1. Its default name is Command1. [/SIZE][/FONT]
[*][FONT=Courier New][SIZE=3]Add the following code to the General Declarations section of Form1: [/SIZE][/FONT]
[/LIST][COLOR=#333333][FONT=Courier New][SIZE=3]  Option Explicit[/SIZE][/FONT][/COLOR]
 
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Const NCBASTAT = &H33[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Const NCBNAMSZ = 16[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Const HEAP_ZERO_MEMORY = &H8[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Const HEAP_GENERATE_EXCEPTIONS = &H4[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Const NCBRESET = &H32[/SIZE][/FONT][/COLOR]
 
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Type NCB[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_command As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_retcode As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_lsn As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_num As Byte ' Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_buffer As Long 'String[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_length As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_callname As String * NCBNAMSZ[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_name As String * NCBNAMSZ[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_rto As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_sto As Byte ' Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_post As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_lana_num As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_cmd_cplt As Byte  'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_reserve(9) As Byte ' Reserved, must be 0[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ncb_event As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  End Type[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Type ADAPTER_STATUS[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       adapter_address(5) As Byte 'As String * 6[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       rev_major As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       reserved0 As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       adapter_type As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       rev_minor As Byte 'Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       duration As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       frmr_recv As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       frmr_xmit As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       iframe_recv_err As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       xmit_aborts As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       xmit_success As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       recv_success As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       iframe_xmit_err As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       recv_buff_unavail As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       t1_timeouts As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       ti_timeouts As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       Reserved1 As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       free_ncbs As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       max_cfg_ncbs As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       max_ncbs As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       xmit_buf_unavail As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       max_dgram_size As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       pending_sess As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       max_cfg_sess As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       max_sess As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       max_sess_pkt_size As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       name_count As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  End Type[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Type NAME_BUFFER[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       name  As String * NCBNAMSZ[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       name_num As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       name_flags As Integer[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  End Type[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Type ASTAT[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       adapt As ADAPTER_STATUS[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]       NameBuff(30) As NAME_BUFFER[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  End Type[/SIZE][/FONT][/COLOR]
 
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Declare Function Netbios Lib "netapi32.dll" _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]          (pncb As NCB) As Byte[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]          hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Declare Function GetProcessHeap Lib "kernel32" () As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Declare Function HeapAlloc Lib "kernel32" _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]          (ByVal hHeap As Long, ByVal dwFlags As Long, _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]          ByVal dwBytes As Long) As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]          ByVal dwFlags As Long, lpMem As Any) As Long[/SIZE][/FONT][/COLOR]
 

[LIST]
[*][FONT=Courier New][SIZE=3]Add the following code to Command1_Click event procedure: [/SIZE][/FONT]
[/LIST][COLOR=#333333][FONT=Courier New][SIZE=3]  Sub Command1_Click()[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      Dim myNcb As NCB[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      Dim bRet As Byte[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      myNcb.ncb_command = NCBRESET[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      bRet = Netbios(myNcb)[/SIZE][/FONT][/COLOR]
 
[COLOR=#333333][FONT=Courier New][SIZE=3]      myNcb.ncb_command = NCBASTAT[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      myNcb.ncb_lana_num = 0[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      myNcb.ncb_callname = "*               "[/SIZE][/FONT][/COLOR]
 
[COLOR=#333333][FONT=Courier New][SIZE=3]      Dim myASTAT As ASTAT, tempASTAT As ASTAT[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      Dim pASTAT As Long[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      myNcb.ncb_length = Len(myASTAT)[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      Debug.Print Err.LastDllError[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]               Or HEAP_ZERO_MEMORY, myNcb.ncb_length)[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      If pASTAT = 0 Then[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]         Debug.Print "memory allcoation failed!"[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]         Exit Sub[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      End If[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      myNcb.ncb_buffer = pASTAT[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      bRet = Netbios(myNcb)[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      Debug.Print Err.LastDllError[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      MsgBox Hex(myASTAT.adapt.adapter_address(0)) & " " & _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]             Hex(myASTAT.adapt.adapter_address(1)) _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]             & " " & Hex(myASTAT.adapt.adapter_address(2)) & " " _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]             & Hex(myASTAT.adapt.adapter_address(3)) _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]             & " " & Hex(myASTAT.adapt.adapter_address(4)) & " " _[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]             & Hex(myASTAT.adapt.adapter_address(5))[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]      HeapFree GetProcessHeap(), 0, pASTAT[/SIZE][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier New][SIZE=3]  End Sub[/SIZE][/FONT][/COLOR]
 

[LIST]
[*][FONT=Courier New][SIZE=3]Press the F5 key to run the program. [/SIZE][/FONT]
[*][FONT=Courier New][SIZE=3]Click on Command1. Note that the network adapter address is displayed in a message box. [/SIZE][/FONT]
[/LIST][/COLOR][/FONT]
 

Users who are viewing this thread

Back
Top Bottom