Japt

ARP Reader - VB.NET

Jul 18th, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Net
  2. Imports System.Runtime.InteropServices
  3.  
  4. '------------------
  5. 'Creator: aeonhack
  6. 'Site: elitevs.net
  7. 'Created: 4/24/2012
  8. 'Changed: 4/24/2012
  9. 'Version: 1.0.0
  10. '------------------
  11.  
  12. Class ARP
  13.  
  14. Private Delegate Function DnsHandler(address As IPAddress) As IPHostEntry
  15. Shared Function ResolveName(address As IPAddress, timeOut As Integer) As String
  16. Try
  17. Dim CB As New DnsHandler(AddressOf Dns.GetHostEntry)
  18. Dim R As IAsyncResult = CB.BeginInvoke(address, Nothing, Nothing)
  19.  
  20. If R.AsyncWaitHandle.WaitOne(timeOut, False) Then
  21. Return CB.EndInvoke(R).HostName
  22. Else
  23. Return String.Empty
  24. End If
  25. Catch ex As Exception
  26. Return String.Empty
  27. End Try
  28. End Function
  29.  
  30. Shared Function ConnectionCache() As IPAddress()
  31. Dim Size As Integer
  32. If Not GetIpNetTable(IntPtr.Zero, Size, False) = 122 Then Return New IPAddress() {}
  33.  
  34. Dim Items As New List(Of IPAddress)
  35. Dim Handle As IntPtr = Marshal.AllocCoTaskMem(Size)
  36.  
  37. If GetIpNetTable(Handle, Size, False) = 0 Then
  38. Dim Pointer As IntPtr
  39. Dim Count As Integer = Marshal.ReadInt32(Handle)
  40.  
  41. For I As Integer = 0 To Count - 1
  42. Pointer = New IntPtr((Handle.ToInt32 + 4) + (I * 24))
  43.  
  44. '3 = Dynamic, 4 = Static
  45. If Marshal.ReadInt32(Pointer, -4) = 3 Then
  46. Dim Address As Integer = Marshal.ReadInt32(Pointer, -8)
  47. Items.Add(New IPAddress(Int32ToUInt32(Address)))
  48. End If
  49. Next
  50. End If
  51.  
  52. Marshal.FreeCoTaskMem(Handle)
  53. Return Items.ToArray()
  54. End Function
  55.  
  56. Private Shared Function Int32ToUInt32(value As Integer) As UInteger
  57. Return BitConverter.ToUInt32(BitConverter.GetBytes(value), 0)
  58. End Function
  59.  
  60. <DllImport("iphlpapi.dll", EntryPoint:="GetIpNetTable")> _
  61. Private Shared Function GetIpNetTable( _
  62. ByVal table As IntPtr, _
  63. ByRef length As Integer, _
  64. ByVal order As Boolean) As UInteger
  65. End Function
  66.  
  67. End Class
Add Comment
Please, Sign In to add comment