473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(respo nse, datastart, datalength);
Console.WriteLi ne(" sysName - Datatype: {0}, Value:
{1}",datatype,o utput);
-/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(respo nse, datastart, datalength);
Console.WriteLi ne(" sysName - Datatype: {0}, Value:
{1}",datatype,o utput);
-/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 1669

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

Similar topics

10
10039
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 software is fine, as it's for a specialised in-house application. I've tried PySNMP which, while a fine piece of code (I've learnt a lot looking through it!), it's fairly CPU intensive in my application. I've also tried using UCDSNMP via...
1
532
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 (even though a SET isn't anymore difficult then a GET or a WALK I don't think).
5
17187
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# code) of some simple snmp commands. All examples I can find are written in C or C#. There is an extensive snmp.h file, but I cannot find the equivalent for VB or figure out how to manually create the equivalent in VB All I need is a starting...
0
1707
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 Apache module) Everything compiles just fine, but when I try to call any of the SNMP functions (i.e. snmpget) from a PHP script on a web page, I get the following error: Warning: snmpget() : Could not open snmp connection: Unknown host in...
0
1394
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
974
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 the SNMP part I have only teoretic knowledge how it works... Do you know something helpful? Every help is wellcomed. Thank you for your time
2
2368
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 this?
2
6984
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 2^14 but some enterprise IDs are now larger than that. Do I just contine the conversion on to additional bytes needed to house the OID in full? So and enterprise ID of 25000 would be sent as three bytes of the following:
5
4597
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
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.