VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,811 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,686 people online right now. Registration is fast and FREE... Join Now!




Help needed Decode SNMP trap in readable string

 

Help needed Decode SNMP trap in readable string, Receiving SNMP trap

Rating  5
v-2rahna

24 Mar, 2009 - 02:01 AM
Post #1

New D.I.C Head
*

Joined: 24 Mar, 2009
Posts: 1

Hi All,

Please find my code below:-

This code uses the WMI query to retrieve the SNMP trap from a particular host
Also find the output of this code listed below:--


Public Function event2() As Boolean

Try

Dim connection As New ConnectionOptions()
' connection.Username = "administrator"
'connection.Password = "Admin#123"
'connection.Authority = "ntlmdomain:DOMAIN"

Dim scope As New ManagementScope("\\localhost\root\snmp\localhost", connection)
scope.Connect()

Dim query As New WqlEventQuery("SELECT * FROM SNMPV1ExtendedNotification")

Dim watcher As New ManagementEventWatcher(scope, query)


Console.WriteLine("Waiting for an event on FullComputerName ...")

Dim eventObj As ManagementBaseObject = watcher.WaitForNextEvent()
watcher.Start()

TrapReceive(eventObj)

Dim s() As System.Management.ManagementBaseObject
Dim ie As System.Collections.IEnumerator

s = eventObj("VarBindList")

ie = s.GetEnumerator

Dim i As Integer
Dim DC As System.Text.Decoder
Dim strConvertToUTF8 As String
Dim byteArr() As Byte


DC = System.Text.Encoding.UTF8.GetDecoder

Console.Write("The array contains the following values")

While ie.MoveNext()

strConvertToUTF8 = s(i).GetText(TextFormat.Mof)
Console.WriteLine("{0}", strConvertToUTF8)

i = i + 1
End While
' Cancel the event subscription
watcher.Stop()

Close()


Catch err As ManagementException

MessageBox.Show("An error occurred while trying to receive an event: " & err.Message)

Catch unauthorizedErr As System.UnauthorizedAccessException

MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)

End Try


End Function

Public Function TrapReceive(ByVal eventObj As ManagementBaseObject) As Boolean

Console.WriteLine("{0} event occurred.", eventObj("__CLASS"))
Console.WriteLine("{0} Community name---> .", eventObj("Community"))

' Display information from the event
Console.WriteLine("Process {0} has created, path is: ", eventObj("__PATH"))
Console.WriteLine("Property count {0}", eventObj("__PROPERTY_COUNT"))
Console.WriteLine("Relative path {0} ", eventObj("__RELPATH"))
Console.WriteLine("Server {0} ", eventObj("__SERVER"))
Console.WriteLine("SUPERCLASS {0} ", eventObj("__SUPERCLASS"))
Console.WriteLine("AgentAddress {0} ", eventObj("AgentAddress"))
Console.WriteLine("AgentTransportAddress {0} ", eventObj("AgentTransportAddress"))
Console.WriteLine("AgentTransportProtocol {0} ", eventObj("AgentTransportProtocol"))
Console.WriteLine("Identification {0} ", eventObj("Identification"))
Console.WriteLine("TimeStamp {0} ", eventObj("TimeStamp"))
Console.WriteLine("VarBindList {0} ", eventObj("VarBindList"))

End Function


OutPut
===========


Waiting for an event on FullComputerName ...
SnmpV1ExtendedNotification event occurred.
public Community name---> .
Process has created, path is:
Property count 9
Relative path
Server
SUPERCLASS SnmpExtendedNotification
AgentAddress 10.217.65.161
AgentTransportAddress 10.217.65.161
AgentTransportProtocol IP
Identification 1.3.6.1.4.1.393.200.50.66.0.3
TimeStamp 20
VarBindList System.Management.ManagementBaseObject[]

The array contains the following values
==========

The following output is the SNMPVArBindlist that has been extracted from a SNMP trap..

I need your help to decode this structure and get it into a readable format.
Please help !!
instance of SnmpVarBind
{
Encoding = "OCTET STRING";
ObjectIdentifier = "1.3.6.1.4.1.393.200.50.66.1.1";
Value = {84, 104, 101, 32, 83, 99, 97, 110, 32, 69, 110, 103, 105, 110, 101, 32, 104, 97, 115, 32, 98, 101, 101, 110, 32, 109, 97, 110, 117, 97, 108, 108, 121, 32, 115, 104, 117, 116, 32, 100, 111, 119, 110};
};


instance of SnmpVarBind
{
Encoding = "OCTET STRING";
ObjectIdentifier = "1.3.6.1.4.1.393.200.50.66.1.2";
Value = {49, 48, 46, 50, 49, 55, 46, 54, 53, 46, 49, 54, 49};
};



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 09:54PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month