View Single Post
Join Date: Nov 2007
Posts: 2,640
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: How to get mac address with input ip address

 
0
  #5
Feb 8th, 2008
Try This following Code :
  1. Option Explicit
  2.  
  3. Private Const No_ERROR = 0
  4.  
  5. Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Long
  6. Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIp As Long, ByVal ScrIP As Long, pMacAddr As Long, PhyAddrLen As Long) As Long
  7. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (dst As Any, src As Any, ByVal bcount As Long)
  8.  
  9. Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, sRemoteMacAddress As String) As Boolean
  10. Dim dwRemoteIp As Long
  11. Dim pMacAddr As Long
  12. Dim bpMacAddr() As Byte
  13. Dim PhyAddrLen As Long
  14. Dim cnt As Long
  15. Dim tmp As String
  16.  
  17. dwRemoteIp = inet_addr(sRemoteIP)
  18. If dwRemoteIp <> 0 Then
  19. PhyAddrLen = 6
  20. If SendARP(dwRemoteIp, 0&, pMacAddr, PhyAddrLen) = No_ERROR Then
  21. If pMacAddr <> 0 And PhyAddrLen <> 0 Then
  22. ReDim bpMacAddr(0 To PhyAddrLen - 1)
  23. CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
  24. For cnt = 0 To PhyAddrLen - 1
  25. If bpMacAddr(cnt) = 0 Then
  26. tmp = tmp & "00-"
  27. Else
  28. tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
  29. End If
  30. Next
  31.  
  32. If Len(tmp) > 0 Then
  33. sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
  34. GetRemoteMACAddress = True
  35. End If
  36.  
  37. Exit Function
  38. Else
  39. GetRemoteMACAddress = False
  40. End If
  41. Else
  42. GetRemoteMACAddress = False
  43. End If
  44. Else
  45. GetRemoteMACAddress = False
  46. End If
  47. End Function
  48.  
  49. Private Sub btnGetMac_Click()
  50. Dim sRemoteMacAddress As String
  51. If Len(txtIpAddress.Text) > 0 Then
  52. If GetRemoteMACAddress(txtIpAddress.Text, sRemoteMacAddress) Then
  53. lblMacAddress.Caption = sRemoteMacAddress
  54. Else
  55. lblMacAddress.Caption = "(SendARP call failed)"
  56. End If
  57. End If
  58. End Sub
Actually this code can use as hacking tool, so use this code carefully friend.

It seems like this pic :
MAC Address.bmp
Last edited by Jx_Man; Feb 8th, 2008 at 11:08 pm. Reason: Pic attach
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote