lextudio / sharpsnmplib

Sharp SNMP Library- Open Source SNMP for .NET
https://sharpsnmp.com
MIT License
356 stars 152 forks source link

OID as String #453

Closed lextudio-support closed 2 days ago

lextudio-support commented 2 days ago

Hi,

Is it possible to specify the following line:
Manager.Walk(VersionCode.V1, IPAddress.Parse(DeviceIP), Community, new ObjectIdentifier(new uint[] { 1, 3, 6, 1, 2, 1, 2, 2 }), WalkList, 1000);

using the string "1.3.6.1.2.1.2.2" rather than the new uint data type? I have been looking at this for a few hours and getting any where. if so, could you give me a quick example

Thanks in advance!

Original Reported Date: 2008-07-30T00:10:15.207-07:00 Original CodePlex Discussion Thread ID: 32528

lextudio-support commented 2 days ago

Copied from CodePlex without authors:

hi, you may use this function written by Andy Hau,

uint[] StringToUint(string s)
{
string[] p = s.Split('.');
uint[] u = new uint[p.Length];
for (int i = 0; i < p.Length; i++)
{
u[i] = uint.Parse(p[i]);
}
return u;
}

Personally, I do not use OID strings that much, so I do not include this helper function in #SNMP.

Original Posted Date: 2008-07-30T19:28:39.473-07:00

lextudio-support commented 2 days ago

Copied from CodePlex without authors:

That works great, many thaks for your quick response!

FunkyGibbon

Original Posted Date: 2008-07-30T23:59:27.893-07:00

lextudio-support commented 2 days ago

Copied from CodePlex without authors:

Please include possibility of specifying OID as string as a constructor for ObjectIdentifier. Usually you are building OIDs starting from a Root OID of your application to which you concatenate Variables OID, Types OID and so on.
String concatenation of OIDs is certainly more natural than working with arrays of uints.

Original Posted Date: 2008-08-05T05:52:25.17-07:00

lextudio-support commented 2 days ago

Copied from CodePlex without authors:

Hi, finally I added this function into ObjectIdentifier.cs in Change Set 14893. It is one of the Convert static methods that convert OIDs between string and array formats.

BTW, I decided to provide as little overloading functions as possible in the core library (SharpSnmpLib.dll). Maybe one day I am going to split all overloading methods into a helper library (SharpSnmpLib.Helpers.dll). I think Extension Method in C# 3.0 provides me a nice way. Stay tuned.

Original Posted Date: 2008-08-05T20:22:14.957-07:00

lextudio-support commented 2 days ago

Copied from CodePlex without authors:

Hi

when I carry out the following line of code

ObjectIdentifier ObjId = new ObjectIdentifier(ObjectIdentifier.Convert("1.3.6.1.4.1.9.9.68.1.2.2.1.2"));

I get the error messages

Textual 'ObjId.Textual' threw an exception of type 'System.ArgumentOutOfRangeException' string {System.ArgumentOutOfRangeException}

Any ideas what the problem might be?

Thanks

Original Posted Date: 2008-08-12T05:51:30.157-07:00

lextudio-support commented 2 days ago

Copied from CodePlex without authors:

If you want to get textual form of an object identifier, please make sure the MIB document containing this object identifier is already loaded in ObjectRegistry. If not, #SNMP cannot provide you the textual form but raise such an exception. (Yes, you are required to provide MIB documents in this case.)

Because I consider it as a design error other than a run-time exception, you see that I do nothing to hide this exception. :-)

-Lex

Original Posted Date: 2008-08-12T20:02:13.163-07:00

lextudio-support commented 2 days ago

Marked as Answer Date: 2013-10-06T21:45:41.777-07:00