473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SNMP, question about how sample code works

greetings,

i am completely new to c# and i'm looking to write a littel util to
extract snmp information from cisco hardware for starters. i have found
some sample code helping me along my way but i'm now looking at a piece
of code which extract the usefull stuff from the responds and cuts away
the useless. this code i don't understand, could someone please tell me
how it works, short and very simple :) ?
here's the code:
-snip-
int commlength, miblength, datatype, datalength, datastart;
int uptime = 0;
string output;
SNMP conn = new SNMP();
byte[] response = new byte[1024];

response = conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.5.0");

commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);

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);
Console.WriteLine(" sysName - Datatype: {0}, Value:
{1}",datatype,output);
-/snip-
this will extract the hostname from the cisco, the part i don't get is this:

-snip-
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);

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);
Console.WriteLine(" sysName - Datatype: {0}, Value:
{1}",datatype,output);
-/snip-

here output is edited in a way to only return the actual hostname, info
like my snmp community, which is included in the response, gets removed,
but i don't quite understand what's happening there :(
this is probably a very lame question and i'd understand any sort of
RTFM reply, but i'd really really appreciate it if someone could take
the time and help me out :)

thanks for reading and any possible responses,
regards,
milan
Nov 17 '05 #1
0 1649

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Matthew Bell | last post by:
Hi, I'm looking for a high-performance SNMP manager toolkit (SNMPv1 / v2, GET / GETNEXT / GETBULK) I can use with Python on Windows2K/XP. I wonder if anyone has got any suggestions? Commercial...
1
by: ZacBowling | last post by:
Does anyone have an idea of how to access the SNMP API or WMI SNMP provider in C#/.NET? I need to query a Ascend MAX's SNMP service with a custom MIB in .NET. I won't be modify anything on the MAX...
5
by: mony | last post by:
I am looking a VB.NET example on how to reference the SNMP API information. I am unable to add references to SNMPAPI.LIB or SNMPAPI.DLL. My goal is to write a 100% VB.NET example (no C or C#...
0
by: Bill | last post by:
I've recently built a new server on which I've tried to configure and install PHP5 (I've now tried 5.0.4, 5.0.5, and 5.1.0RC1) along with Apache 1.3.33 and net-snmp 5.2.1.2. (Building PHP5 as an...
0
by: viva_KAO | last post by:
is there any c# sample for snmp agent ? it works like a server to respond snmp UDP request .
0
by: Michal Mynáø | last post by:
Hello all, I am trying to create my own SNMP browser objects, but I can't find any usefull sample. I have some rough idea, that it needs to be solved via Winsock object (allready known), but on...
2
by: Sleurhutje | last post by:
Hi, I need to add SNMP functionality to an existing app. I need to be able to read specific real-time data from another system using SNMP traps. Anyone know a good sample or libs that can do...
2
by: Jason James | last post by:
Guys, can anyone confirm the process on converting the OID into an array of bytes for sending to the SNMP device. The code I have seems to only work for values in the OID that are less than...
5
by: Rainer Queck | last post by:
Hello NG, I would greatly appreciate a code sample on how to connect to a SNMP device using WMI. Regards Rainer Queck
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.