DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   How to get mac address with input ip address (http://www.daniweb.com/forums/thread108137.html)

JoJo1811 Aug 4th, 2009 10:37 pm
Re: How to get mac address with input ip address
 
Quote:

Originally Posted by Jx_Man (Post 530207)
Try This following Code :
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 ScrIP As Long, pMacAddr As Long, PhyAddrLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (dst As Any, src As Any, ByVal bcount As Long)

Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, sRemoteMacAddress As String) As Boolean
    Dim dwRemoteIp As Long
    Dim pMacAddr As Long
    Dim bpMacAddr() As Byte
    Dim PhyAddrLen As Long
    Dim cnt As Long
    Dim tmp As String
   
    dwRemoteIp = inet_addr(sRemoteIP)
    If dwRemoteIp <> 0 Then
        PhyAddrLen = 6
        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
                For cnt = 0 To PhyAddrLen - 1
                    If bpMacAddr(cnt) = 0 Then
                        tmp = tmp & "00-"
                    Else
                        tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
                    End If
                Next
               
                If Len(tmp) > 0 Then
                    sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
                    GetRemoteMACAddress = True
                End If
               
                Exit Function
            Else
                GetRemoteMACAddress = False
            End If
        Else
            GetRemoteMACAddress = False
        End If
    Else
        GetRemoteMACAddress = False
    End If
End Function

Private Sub btnGetMac_Click()
Dim sRemoteMacAddress As String
If Len(txtIpAddress.Text) > 0 Then
    If GetRemoteMACAddress(txtIpAddress.Text, sRemoteMacAddress) Then
        lblMacAddress.Caption = sRemoteMacAddress
    Else
        lblMacAddress.Caption = "(SendARP call failed)"
    End If
End If
End Sub
Actually this code can use as hacking tool, so use this code carefully friend.

It seems like this pic :
Attachment 5027

hi, i would like to enquiry about the following:
lblMacAddress.Caption --> is this a label in visual studio? if not,what do i use?
CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen -
byMacAddr error: Method arguement must be enclosed in parenthesis
ByVal error: expression expected.
Left$ --> has no parameters and return type cannot be indexed.

i am currently using visual studio 2005. Kindly help me regarding the mentioned issue . Thanks!

luquin Aug 26th, 2009 3:47 am
Re: How to get mac address with input ip address
 
i was long searching for that code that estalla asked... though i could copy that code, is it ok for you if i will try to use it also? thanks, so much!

please...

luquin Aug 26th, 2009 3:50 am
Re: How to get mac address with input ip address
 
i was long searching for such code estella asked... though i could copy it, can ask your permission to use it also? please... my purpose is educational... please sir...


All times are GMT -4. The time now is 7:31 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC