Getting little square characters instead of Text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Madiha Ahmed
    New Member
    • Jul 2011
    • 4

    Getting little square characters instead of Text

    I am sending SNMP SystemName query to local host and in response i m getting little square characters instead of the specific system name..

    Code:
    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
        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.115.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)
    And this is the output m getting

    Device SNMP Information:

    sysName - Datatype: 48, [][][][]
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I don't know what SNMP is but are you sure the data is ASCII encoded? Those square boxes that are displayed are usually because the data contains undisplayable characters. This means one of two things, either it uses a different character encoding scheme or the data is binary. In the former case, you will have to use the correct encoding. In the latter case, you should display it as hex.

    Comment

    Working...