www.pudn.com > NetMgrSamp1.rar > frmSNMP3.frm
VERSION 5.00
Begin VB.Form frmSNMP3
Caption = "NetMgr -- SNMP Sample 3 [VB]"
ClientHeight = 4395
ClientLeft = 60
ClientTop = 345
ClientWidth = 4695
LinkTopic = "Form1"
ScaleHeight = 4395
ScaleWidth = 4695
StartUpPosition = 2 'CenterScreen
Begin VB.ListBox lstResults
Height = 1035
ItemData = "frmSNMP3.frx":0000
Left = 0
List = "frmSNMP3.frx":0007
TabIndex = 23
Top = 3360
Width = 4695
End
Begin VB.Frame fmeHostInfo
Caption = "Host Information"
Height = 1575
Left = 0
TabIndex = 14
Top = 0
Width = 4695
Begin VB.TextBox txtRetries
Height = 285
Left = 3480
TabIndex = 18
Text = "2"
Top = 1080
Width = 375
End
Begin VB.TextBox txtTimeout
Height = 285
Left = 1680
TabIndex = 17
Text = "1000"
Top = 1080
Width = 855
End
Begin VB.TextBox txtCommStr
Height = 285
Left = 1680
TabIndex = 16
Text = "public"
Top = 720
Width = 1575
End
Begin VB.TextBox txtAgent
Height = 285
Left = 1680
TabIndex = 15
Text = "127.0.0.1"
Top = 360
Width = 1575
End
Begin VB.Label lblTimeout
Alignment = 1 'Right Justify
Caption = "Timeout [ms]"
Height = 255
Left = 240
TabIndex = 22
Top = 1080
Width = 1335
End
Begin VB.Label lblRetries
Alignment = 1 'Right Justify
Caption = "Retries"
Height = 255
Left = 2640
TabIndex = 21
Top = 1125
Width = 735
End
Begin VB.Label lblCommStr
Alignment = 1 'Right Justify
Caption = "Community String"
Height = 255
Left = 240
TabIndex = 20
Top = 720
Width = 1335
End
Begin VB.Label lblAgent
Alignment = 1 'Right Justify
Caption = "SNMP Agent "
Height = 255
Left = 240
TabIndex = 19
Top = 390
Width = 1335
End
End
Begin VB.Frame fmeSpecs
Caption = "OID Specifications"
Height = 1575
Left = 0
TabIndex = 1
Top = 1680
Width = 4695
Begin VB.CheckBox chkSetInteger
Caption = "Integer"
Enabled = 0 'False
Height = 255
Left = 2880
TabIndex = 10
Top = 615
Visible = 0 'False
Width = 855
End
Begin VB.CommandButton cmdGo
Caption = "Go!"
Height = 375
Left = 3840
TabIndex = 9
Top = 240
Width = 735
End
Begin VB.CheckBox chkFullWalk
Caption = "Full Walk"
Height = 255
Left = 3360
TabIndex = 8
Top = 1170
Visible = 0 'False
Width = 1095
End
Begin VB.TextBox txtSetVal
Enabled = 0 'False
Height = 285
Left = 1440
TabIndex = 7
Top = 600
Width = 1215
End
Begin VB.OptionButton optOps
Caption = "Walk"
Height = 195
Index = 3
Left = 2160
TabIndex = 6
Top = 1200
Width = 735
End
Begin VB.OptionButton optOps
Caption = "Set"
Height = 195
Index = 2
Left = 1440
TabIndex = 5
Top = 1200
Width = 615
End
Begin VB.OptionButton optOps
Caption = "GetNext"
Height = 195
Index = 1
Left = 2160
TabIndex = 4
Top = 960
Width = 975
End
Begin VB.OptionButton optOps
Caption = "Get"
Height = 195
Index = 0
Left = 1440
TabIndex = 3
Top = 960
Width = 615
End
Begin VB.TextBox txtOID
Height = 285
Left = 1440
TabIndex = 2
Text = "1.3.6.1.2.1.1.3.0"
Top = 240
Width = 2295
End
Begin VB.Label lblSetVal
Alignment = 1 'Right Justify
Caption = "Set Value"
Height = 255
Left = 120
TabIndex = 13
Top = 645
Width = 1215
End
Begin VB.Label lblOps
Alignment = 1 'Right Justify
Caption = "Operations"
Height = 255
Left = 120
TabIndex = 12
Top = 960
Width = 1215
End
Begin VB.Label lblOID
Alignment = 1 'Right Justify
Caption = "Object Identifier"
Height = 255
Left = 120
TabIndex = 11
Top = 285
Width = 1215
End
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 2640
TabIndex = 0
Top = 4680
Width = 1935
End
End
Attribute VB_Name = "frmSNMP3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Global variable declarations
' ----------------------------
Private intOps As Integer
Private Sub cmdGo_Click()
' Local variable declarations
' ------------------------------
Dim tObj As Object ' NetMgrVB Object
Dim matchOID As Variant ' Used for OID comparison in SNMP walks
Dim varOID As String ' Encapsulates OID
Dim strAgentVal As String ' Utility string variable
Dim intRetVal As Integer ' Utility integer variable
Dim intCounter As Integer ' Counter
' Initialize NetMgrVB Object
Set tObj = CreateObject("NetMgrVB.SnmpV1")
' Remove all results
lstResults.Clear
' Assign value to varOID
varOID = txtOID.Text
' Open connection and return value of oid -> operation
With tObj
' Initialize properties
.Agent = txtAgent.Text
.CommStr = txtCommStr.Text
.Timeout = CInt(txtTimeout.Text)
.Retry = CInt(txtRetries.Text)
' Opening Connection and add item to list view
strAgentVal = .SnmpMgrOpen
lstResults.AddItem "> " & strAgentVal
lstResults.AddItem "=D= Debug Mode ON"
DoEvents
' OutputDebugString "Howdy!"
' Get value for OID if no error is returned
If strAgentVal = "Successful" Then
' Execute statements in accordance with selected operation
Select Case intOps
Case 0 ' Operation -> Get
lstResults.AddItem "=D= Case 0 starting get"
DoEvents
strAgentVal = .SnmpGet(varOID)
' OutputDebugString "[APP:1]"
lstResults.AddItem "=== " & varOID & " : " & strAgentVal
' OutputDebugString "[APP:2]"
Case 1 ' Operation -> GetNext
strAgentVal = .SnmpGetNext(varOID)
lstResults.AddItem "=== " & varOID & " : " & strAgentVal
Case 2 ' Operation -> Set
' =Validate if the Integer checkbox is checked
' ==Not Checked therefore assume String type
If chkSetInteger.Value = 0 Then
lstResults.AddItem "=== " & varOID & " : " & .SnmpSet(varOID, txtSetVal.Text, 0)
Else
' ==Checked therefore assume Integer type
' Double text box and sure it is an integer
If IsNumeric(txtSetVal.Text) Then
lstResults.AddItem "=== " & varOID & " : " & .SnmpSet(varOID, CLng(txtSetVal.Text), 1)
Else
lstResults.AddItem "=== " & varOID & " does not appear to be an integer"
End If
End If
Case 3 ' Walk
' Initialize walk
strAgentVal = tObj.SnmpGet(varOID)
lstResults.AddItem "=S= " & varOID & " : " & strAgentVal
intCounter = 2
' Grab first oid/value pair after txtOID.text
strAgentVal = CStr(.SnmpGetNext(varOID))
matchOID = Mid(varOID, 1, InStr(1, varOID, ".", 1))
lstResults.AddItem "=1= " & varOID & " : " & strAgentVal
' Loop through all oid's in criteria
Do Until (InStr(1, strAgentVal, "Error", 1) > 0 Or InStr(1, varOID, ".iso.", 1) > 0)
' Get Next Value
strAgentVal = CStr(.SnmpGetNext(varOID))
' Validate life cycle of walk
If chkFullWalk.Value = 0 Then
' When using the SnmpMgrOidToStr function in the WinSNMP API, the LPSTR
' returned is the the actual name of the OID. The purpose of statements
' dealing with matchOID is to make sure that we're staying within the same
' area IF the Full Walk check box is unchecked.
If Mid(varOID, 1, InStr(1, varOID, ".", 1)) <> matchOID Then
matchOID = Mid(varOID, 1, InStr(1, varOID, ".", 1))
Exit Do
End If
End If
' Add item to list view
lstResults.AddItem "=" & intCounter & "= " & varOID & " : " & strAgentVal
' Increment counter
intCounter = intCounter + 1
' Make sure list view gets updated
DoEvents
Loop
End Select
End If
' OutputDebugString "Closing.."
' Close connection and return result
lstResults.AddItem "> " & IIf(.SnmpMgrClose = "Successful", "Closed connection successfully", "Error with closing connection")
End With
' Destory object
Set tObj = Nothing
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
' Clear items from list view
lstResults.Clear
' Assign default to Operation Options and global
' variable intOps
optOps(0).Value = True
intOps = 0
End Sub
Private Sub Form_Resize()
' Upon resizing of form, make sure listview and lines
' change with the form
If (lstResults.Top < Me.Height) Then
lstResults.Width = Me.Width - lstResults.Left - 100
lstResults.Height = Me.Height - lstResults.Top - 100
End If
fmeHostInfo.Width = lstResults.Width - 25
fmeSpecs.Width = lstResults.Width - 25
End Sub
Private Sub optOps_Click(Index As Integer)
' Assign index to global variable intOps
intOps = Index
' Execute commands based upon which option is chosen
Select Case Index
Case 2 ' Operation -> Set
txtSetVal.Enabled = True
chkSetInteger.Visible = True
chkSetInteger.Enabled = True
chkFullWalk.Visible = False
chkFullWalk.Value = 0
Case 3 ' Walk
txtSetVal.Enabled = False
chkSetInteger.Visible = False
chkSetInteger.Enabled = False
chkSetInteger.Value = 0
chkFullWalk.Visible = True
Case Else ' All other operations
txtSetVal.Enabled = False
chkSetInteger.Visible = False
chkSetInteger.Enabled = False
chkSetInteger.Value = 0
chkFullWalk.Visible = False
chkFullWalk.Value = 0
End Select
End Sub