Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Mac Addresses - frmMacAddresses.frm

frmMacAddresses.frm

Caricato da: Antometal
Scarica il programma completo

  1. Private Const ERROR_SUCCESS = 0&
  2. Private Const ERROR_NOT_SUPPORTED = 50&
  3.  
  4. Private Type MIB_IFROW
  5. wszName(0 To 511) As Byte
  6. dwIndex As Long '// index of the interface
  7. dwType As Long '// type of interface
  8. dwMtu As Long '// max transmission unit
  9. dwSpeed As Long '// speed of the interface
  10. dwPhysAddrLen As Long '// length of physical address
  11. bPhysAddr(0 To 7) As Byte '// physical address of adapter
  12. dwAdminStatus As Long '// administrative status
  13. dwOperStatus As Long '// operational status
  14. dwLastChange As Long '// last time operational status changed
  15. dwInOctets As Long '// octets received
  16. dwInUcastPkts As Long '// unicast packets received
  17. dwInNUcastPkts As Long '// non-unicast packets received
  18. dwInDiscards As Long '// received packets discarded
  19. dwInErrors As Long '// erroneous packets received
  20. dwInUnknownProtos As Long '// unknown protocol packets received
  21. dwOutOctets As Long '// octets sent
  22. dwOutUcastPkts As Long '// unicast packets sent
  23. dwOutNUcastPkts As Long '// non-unicast packets sent
  24. dwOutDiscards As Long '// outgoing packets discarded
  25. dwOutErrors As Long '// erroneous packets sent
  26. dwOutQLen As Long '// output queue length
  27. dwDescrLen As Long '// length of bDescr member
  28. bDescr(0 To 255) As Byte '// interface description
  29. End Type
  30.  
  31.  
  32. Private Declare Function GetIfTable Lib "iphlpapi" (ByRef pIfRowTable As Any, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
  33. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByRef pSource As Any, ByVal Length As Long)
  34.  
  35.  
  36. Private Function MacAddress() As String
  37. Dim arrBuffer() As Byte
  38. Dim lngSize As Long
  39. Dim lngRetVal As Long
  40. Dim lNetCards As Long
  41. Dim i As Integer
  42. Dim j As Integer
  43. Dim IfRowTable As MIB_IFROW
  44. Dim sAddr As String
  45. Dim sName As String
  46. Dim Info As String
  47.  
  48. lngSize = 0
  49.  
  50. 'Call the GetIfTable just to get the buffer size into the lngSize variable
  51. lngRetVal = GetIfTable(ByVal 0&, lngSize, 0)
  52.  
  53.     If lngRetVal = ERROR_NOT_SUPPORTED Then
  54.         'This API works only on Win 98/2000 and NT4 with SP4
  55.         MsgBox "IP Helper is not supported by this system."
  56.         Exit Function
  57.     End If
  58.    
  59. 'Prepare the buffer
  60. ReDim arrBuffer(0 To lngSize - 1) As Byte
  61.  
  62. 'And call the function one more time
  63. lngRetVal = GetIfTable(arrBuffer(0), lngSize, 0)
  64.  
  65.     If lngRetVal = ERROR_SUCCESS Then
  66.         'The first 4 bytes contain the quantity of the network cards
  67.         'Get that value into the lNetCards variable
  68.         CopyMemory lNetCards, arrBuffer(0), 4
  69.  
  70.             For i = 1 To lNetCards
  71.                 'Copy the network data to the IfRowTable structure
  72.                 CopyMemory IfRowTable, arrBuffer(4 + (i - 1) * Len(IfRowTable)), Len(IfRowTable)
  73.            
  74.                 'Retrieve name of the network card
  75.                 sName = ""
  76.                 sName = Replace$(Left(StrConv(IfRowTable.bDescr, vbUnicode), IfRowTable.dwDescrLen), vbNullChar, vbNullString)
  77.                 Info = Info & sName & vbCrLf
  78.    
  79.                 'Rertieve MAK address
  80.                     If IfRowTable.dwPhysAddrLen > 0 Then
  81.                         sAddr = ""
  82.                             For j = 0 To IfRowTable.dwPhysAddrLen - 1
  83.                                 sAddr = sAddr & CStr(IIf(IfRowTable.bPhysAddr(j) = 0, "00", Hex(IfRowTable.bPhysAddr(j)))) & "-"
  84.                             Next
  85.                         sAddr = Left(sAddr, Len(sAddr) - 1)
  86.                         Info = Info & sAddr & vbCrLf & vbCrLf
  87.                     End If
  88.             Next
  89.     End If
  90.    
  91. MacAddress = Info
  92. End Function
  93.  
  94. Private Sub Form_Load()
  95. txtmac = MacAddress
  96. End Sub