问题描述
美好的一天,
我正在尝试从Sharp-Snmp示例中找出这段代码。
https://github.com/lextudio/sharpsnmplib-samples/blob/master/Samples/VB.NET/snmpset/Program.vb
我正在使用vb.net SET示例。
Public Sub New(id As Lextm.SharpSnmpLib.ObjectIdentifier,data As Lextm.SharpSnmpLib.ISnmpData)
Member of Lextm.SharpSnmpLib.Variable
Public Sub New(id As UInteger(),data As Lextm.SharpSnmpLib.ISnmpData)
Member of Lextm.SharpSnmpLib.Variable
我的Name语法是否错误,或者它必须是OID整数?当我使用OID时,它会运行,而当我使用它的名称时,它就会死掉。
System_Operation_Mode.0 'name
1.3.6.1.4.1.21703.100.1.1.0 'oid
这是SET样本的一部分,死于代码底部的星号**。 用上面的名称而不是OID填写Extra(i)。
ReDim args(3)
args(0) = "192.168.45.5" 'IP Address
args(1) = NetworkConfig.addrModeStringCommand 'command string name System_Operation_Mode.0
args(2) = "i" 'tell it what data type you are sending
args(3) = NetworkConfig.StaticMode 'mode you want from the IPNetwork,in this case static
Dim p As OptionSet = New OptionSet().Add("c:","Community name,(default is public)",Sub(v As String)
If v IsNot nothing Then
community = v
End If
End Sub) _
.Add("l:","Security level,(default is noAuthnopriv)",Sub(v As String)
If v.toupperInvariant() = "NOAUTHnopRIV" Then
level = Levels.Reportable
ElseIf v.toupperInvariant() = "AUTHnopRIV" Then
level = Levels.Authentication Or Levels.Reportable
ElseIf v.toupperInvariant() = "AUTHPRIV" Then
level = Levels.Authentication Or Levels.Privacy Or Levels.Reportable
Else
Throw New ArgumentException("no such security mode: " & v)
End If
End Sub) _
.Add("a:","Authentication method (MD5 or SHA)",Sub(v As String)
authentication = v
End Sub) _
.Add("A:","Authentication passphrase",Sub(v As String)
authPhrase = v
End Sub) _
.Add("x:","Privacy method",Sub(v As String)
privacy = v
End Sub) _
.Add("X:","Privacy passphrase",Sub(v As String)
privPhrase = v
End Sub) _
.Add("u:","Security name",Sub(v As String)
user = v
End Sub) _
.Add("C:","Context name",Sub(v As String)
contextName = v
End Sub) _
.Add("h|?|help","Print this help information.",Sub(v As String)
showHelp__1 = v IsNot nothing
End Sub) _
.Add("V","display version number of this application.",Sub(v As String)
showVersion = v IsNot nothing
End Sub) _
.Add("d","display message dump",Sub(v As String)
dump = True
End Sub) _
.Add("t:","Timeout value (unit is second).",Sub(v As String)
timeout = Integer.Parse(v) * 1000
End Sub) _
.Add("r:","Retry count (default is 0)",Sub(v As String)
retry = Integer.Parse(v)
End Sub) _
.Add("v:","SNMP version (1,2,and 3 are currently supported)",Sub(v As String)
Select Case Integer.Parse(v)
Case 1
version = VersionCode.V1
Exit Select
Case 2
version = VersionCode.V2
Exit Select
Case 3
version = VersionCode.V3
Exit Select
Case Else
Throw New ArgumentException("no such version: " & v)
End Select
End Sub)
If args.Length = 0 Then
ShowHelp(p)
Return
End If
Dim extra As List(Of String)
Try
extra = p.Parse(args)
Catch ex As OptionException
Console.WriteLine(ex.Message)
Return
End Try
If showHelp__1 Then
ShowHelp(p)
Return
End If
If (extra.Count - 1) Mod 3 <> 0 Then
Console.WriteLine("invalid variable number: " & extra.Count)
Return
End If
If showVersion Then
Console.WriteLine(Reflection.Assembly.GetExecutingAssembly().GetName().Version)
Return
End If
Dim ip As IPAddress
Dim parsed As Boolean = IPAddress.TryParse(extra(0),ip)
If Not parsed Then
For Each address As IPAddress In Dns.GetHostAddresses(extra(0))
If address.AddressFamily <> AddressFamily.InterNetwork Then
Continue For
End If
ip = address
Exit For
Next
If ip Is nothing Then
Console.WriteLine("invalid host or wrong IP address found: " & extra(0))
Return
End If
End If
Try
Dim vList As New List(Of Variable)()
Dim i As Integer = 1
While i < extra.Count
Dim type As String = extra(i + 1)
If type.Length <> 1 Then
Console.WriteLine("invalid type string: " & type)
Return
End If
Dim data As ISnmpData
Select Case type(0)
Case "i"c
data = New Integer32(Integer.Parse(extra(i + 2)))
Exit Select
Case "u"c
data = New Gauge32(UInteger.Parse(extra(i + 2)))
Exit Select
Case "t"c
data = New TimeTicks(UInteger.Parse(extra(i + 2)))
Exit Select
Case "a"c
data = New IP(IPAddress.Parse(extra(i + 2)).GetAddressBytes())
Exit Select
Case "o"c
data = New ObjectIdentifier(extra(i + 2))
Exit Select
Case "x"c
data = New OctetString(Bytetool.Convert(extra(i + 2)))
Exit Select
Case "s"c
data = New OctetString(extra(i + 2))
Exit Select
Case "d"c
data = New OctetString(Bytetool.ConvertDecimal(extra(i + 2)))
Exit Select
Case "n"c
data = New Null()
Exit Select
Case Else
Console.WriteLine("unkNown type string: " & type(0))
Return
End Select
Dim test As New Variable(*New ObjectIdentifier(extra(i))*,data)
vList.Add(test)
i = i + 3
End While
我一直在使用“名称”而不是“ OID”来进行更改,以便它可以读取或转换它们?还是我必须回去使用OID?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)