Here is the class, see if you missed any of the fixes.Besides the change you had there were a few others here i had to make also.
my main form imports:
Imports System.Text
Imports System.Net
Imports System.Management (Also had to add the reference to System.Management)
Imports TestAp1.SNMP (which is the class)
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Class SNMP
Public Sub New()
End Sub
Public Function [get](ByVal request As String, ByVal host As String, ByVal community As String, ByVal mibstring As String) As Byte()
Dim packet As Byte() = New Byte(1023) {}
Dim mib As Byte() = New Byte(1023) {}
Dim snmplen As Integer
Dim comlen As Integer = community.Length
Dim mibvals As String() = mibstring.Split("."c)
Dim miblen As Integer = mibvals.Length
Dim cnt As Integer = 0, temp As Integer, i As Integer
Dim orgmiblen As Integer = miblen
Dim pos As Integer = 0 - 1
For i = 0 To orgmiblen - 1
temp = Convert.ToInt16(mibvals(i))
If temp > 127 Then
mib(cnt) = Convert.ToByte(128 + (temp \ 128))
mib(cnt + 1) = Convert.ToByte(temp - ((temp \ 128) * 128))
cnt += 2
miblen += 1
Else
mib(cnt) = Convert.ToByte(temp)
cnt += 1
End If
Next
snmplen = 29 + comlen + miblen - 1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H30
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(snmplen - 2)
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H2
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H4
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(comlen)
Dim data As Byte() = Encoding.ASCII.GetBytes(community)
For i = 0 To data.Length - 1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = data(i)
Next
If request = "get" Then
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &HA0
Else
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &HA1
End If
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(20 + miblen - 1)
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H2
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H4
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H2
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H2
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H30
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(6 + miblen - 1)
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H30
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(6 + miblen - 1 - 2)
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H6
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(miblen - 1)
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H2B
For i = 2 To miblen - 1
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = Convert.ToByte(mib(i))
Next
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H5
packet(System.Math.Max(System.Threading.Interlocked.Increment(pos), pos - 1)) = &H0
Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000)
Dim ihe As IPHostEntry = Dns.GetHostEntry(host)
Dim iep As New IPEndPoint(ihe.AddressList(0), 161)
Dim ep As EndPoint = DirectCast(iep, EndPoint)
sock.SendTo(packet, snmplen, SocketFlags.None, iep)
Try
Dim recv As Integer = sock.ReceiveFrom(packet, ep)
Catch generatedExceptionName As SocketException
packet(0) = &HFF
End Try
Return packet
End Function
End Class