EjemplosDuoc.es.tl
  Obtener MAC VB6
 
Para obtener la mac de una maquina se debe seguir los siguiente pasos:

Crear un modulo o modulo de clase.
Insertar el siguiente codigo:

Option Explicit
Private Const NO_ERROR = 0
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Long
Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Long, ByVal SrcIP As Long, pMacAddr As Long, PhyAddrLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dst As Any, src As Any, ByVal bcount As Long)

Public Function GetRemoteMACAddress(ByVal sRemoteIP As String, sRemoteMacAddress As String, sDelimiter As String) As Boolean
Dim dwRemoteIP As Long
Dim pMacAddr As Long
Dim bpMacAddr() As Byte
Dim PhyAddrLen As Long
dwRemoteIP = ConvertIPtoLong(sRemoteIP)
If dwRemoteIP <> 0 Then
    PhyAddrLen = 6
    GetRemoteMACAddress = False
    If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
        If (pMacAddr <> 0) And (PhyAddrLen <> 0) Then
            ReDim bpMacAddr(0 To PhyAddrLen - 1)
            CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
            sRemoteMacAddress = MakeMacAddress(bpMacAddr(), sDelimiter)
            GetRemoteMACAddress = True
        End If
    End If
End If
End Function

Public Function ConvertIPtoLong(sIpAddress) As Long
ConvertIPtoLong = inet_addr(sIpAddress)
End Function

Public Function MakeMacAddress(b() As Byte, sDelim As String) As String
Dim cnt As Long
Dim buff As String
On Local Error GoTo MakeMac_error
If UBound(b) = 5 Then
    For cnt = 0 To 4
        buff = buff & Right$("00" & Hex(b(cnt)), 2) & sDelim
    Next
    buff = buff & Right$("00" & Hex(b(5)), 2)
End If
MakeMacAddress = buff

MakeMac_exit:
Exit Function

MakeMac_error:
MakeMacAddress = "(error MAC address)"
Resume MakeMac_exit
End Function

Luego en el formulario destinado a la obtencion de la MAC insertar un componente
winsock, este es llamado desde:
agregar el componente -> Controles --> Microsoft Winsock Control 6.0

Luego, en el evento elegido para la obtencion de la MAC agregar:

Dim MAC As New ClsMac -- si es un modulo de clase, sino, excluir
Dim sRemoteMacAddress As String
Winsock1.RemoteHost = Winsock1.LocalHostName
If Len(Text1.text) > 0 Then
    If MAC.GetRemoteMACAddress(Winsock1.LocalIP, sRemoteMacAddress, "-") Then
        Text2.text = sRemoteMacAddress
    Else
    Text2.text = "(SendARP error en llamado)"
    End If
End If

Listo!

Extraido de alguna pagina por ahi que no recuerdo ahora.
 
   
 
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis