开发者

SNMP Packet is not reaching destination

I have SNMP Class which creates the SNMP packet and then create a UDP socket to send the packet..but when I use this class to send Get Packet then I m not getting any response...i have come to this point that packet is not going to its destin开发者_运维百科ation because i used wireshark to check if some traffic is going from udp port 161 but I m not getting any traffic when I debug my program....here is the part of the class that creates the socket:

 Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)

        sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 4500)

        ' Dim ihe As IPHostEntry = Dns.GetHostEntry(host)

        Dim iep As New IPEndPoint(IPAddress.Parse(host), 161)

        Dim ep As EndPoint = DirectCast(iep, EndPoint)

        sock.SendTo(packet, snmplen, SocketFlags.None, iep)

        udp1.Send(packet, packet.Length, iep)

        'Receive response from packet

        Try

            Dim recv As Integer = sock.ReceiveFrom(packet, ep)

        Catch generatedExceptionName As SocketException

            packet(0) = &HFF

            End Try

            Return packet

and this is code of which I use to send SNMP get packet

Imports System.Text

Class Form1

    Dim commlength As Integer, miblength As Integer, datatype As Integer, datalength As Integer, datastart As Integer

    Dim uptime As Integer = 0

    Dim output As String

    Dim conn As New SNMP()

    Dim response As Byte() = New Byte(1023) {}

    ' Public Shared Sub Main(ByVal argv As String())

    'End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        IPaddress.Text = "115.186.118.188"

        Community.Text = "public"



    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        ListBox1.Items.Add("Device SNMP information:")



        ' Send sysName SNMP request

        response = conn.[get]("get", IPaddress.Text, Community.Text, "1.3.6.1.2.1.1.5.0")

        If response(0) = &HFF Then

            ListBox1.Items.Add("No response from " & IPaddress.Text)

            Return

        End If



        ' If response, get the community name and MIB lengths

        commlength = Convert.ToInt16(response(6))

        miblength = Convert.ToInt16(response(23 + commlength))



        ' Extract the MIB data from the SNMP response

        datatype = Convert.ToInt16(response(24 + commlength + miblength))

        datalength = Convert.ToInt16(response(25 + commlength + miblength))

        datastart = 26 + commlength + miblength

        output = Encoding.ASCII.GetString(response, datastart, datalength)

        ListBox1.Items.Add("  sysName - Datatype:" & datatype & "," & output)

End Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜